现在我已经升级了我的 jQuery,我收到了无效标签错误。我读到新的 1.5 版本现在对 JSON 编码更加严格。虽然我使用 Zend_Json::encode(array("content"=>$result)); 对 HTML 进行编码,所以我想这会。
我在手册中读到它已经更新,尽管在没有解析错误的情况下无法让它工作。 jQuery JSON 手册
Error: invalid label
Source File: http://domain.local/register/#
Line: 0, Column: 1
Source Code:
{"content":"<div id=\"captcha_captcha.json\">\r\n<div class=\"input\">\r\n\t<div class=\"text-small\"><input type=\"text\" size=\"12\" name=\"captcha.json[input]\" id=\"captcha_id\" \/><\/div> \r\n\t<img src=\"http:\/\/domain.local\/tmp\/captchas
这是我的 JavaScript 代码。
function regenerateCaptcha<?php echo $params["name"]?>(){
captcha_id = "captcha_<?php echo $params["name"]?>";
$.getJSON("/default/captcha/regeneratecaptcha/name/<?php echo $params["name"]?>.json", function(data){
success : pasteCaptcha<?php echo $params["name"]?>
});
}
function pasteCaptcha<?php echo $params["name"]?>(json){
$("#captcha_<?php echo $params["name"]?> .input").replaceWith(json.content);
}
当我查看 URL 的来源时:
{"content":"<div id=\"captcha_captcha\">\r\n<div class=\"input\">\r\n\t<div class=\"text-small\"><input type=\"text\" size=\"12\" name=\"captcha[input]\" id=\"captcha_id\" \/><\/div> \r\n\t<img src=\"http:\/\/fantasyolympics.local\/tmp\/captchas\/6498c75d8e3f9b8ed2cbb7a066f962a6.png\" class=\"captcha\" width=\"185\" height=\"36\" \/>\r\n <input type=\"hidden\" name=\"captcha[id]\" value=\"6498c75d8e3f9b8ed2cbb7a066f962a6\" \/> \r\n <a href=\"#\" onclick=\"regenerateCaptchacaptcha();return false;\" class=\"captcha_refresh\" title=\"Try a new code\"><\/a>\t\r\n<\/div>\r\n<\/div>\r\n<script type=\"text\/javascript\">\r\n\tfunction regenerateCaptchacaptcha(){\r\n\t\tcaptcha_id = \"captcha_captcha\";\r\n\r\n\t\t$.getJSON(\"\/default\/captcha\/regeneratecaptcha\/name\/captcha.json\", function(data){\r\n success : pasteCaptchacaptcha\t });\r\n\t} \r\n\t\r\n\tfunction pasteCaptchacaptcha(json){\r\n\t\t$(\"#captcha_captcha .input\").replaceWith(json.content);\r\n\t}\r\n<\/script>\r\n"}