“无效标签” $.POST 方法中的 JSON 错误
这是我的脚本
$(document).ready(function() {
$.post(
"admin.php",
{ action: $(this).attr("action") },
function(data) {
data = eval("(" + data + ")");
alert(data);
//alert(data.message);
},"json"
);
});
当我使用基本的 html 页面运行此代码时,它可以工作。但是当我在实际页面中使用相同的脚本时,它会给出“无效标签”错误。
我的 PHP 代码,用于创建 json 字符串
$return = array("status"=>"true","message"=>"A new ".$this->title." has been added");
$json = json_encode($return);
return $json;
的错误控制台收到的错误
invalid label
[Break On This Error] {"status":"true","message":"A new CMS Type has been added"}
http://localhost/admin/admin.php?menu=2
Line 0
在 firebug帮助
Here is my Script
$(document).ready(function() {
$.post(
"admin.php",
{ action: $(this).attr("action") },
function(data) {
data = eval("(" + data + ")");
alert(data);
//alert(data.message);
},"json"
);
});
When I run this code, with the basic html page, it works. But when I use the same script in my actual page, it gives "invalid label" error.
My PHP code, to create the json string
$return = array("status"=>"true","message"=>"A new ".$this->title." has been added");
$json = json_encode($return);
return $json;
The error received at the the errors console at firebug
invalid label
[Break On This Error] {"status":"true","message":"A new CMS Type has been added"}
http://localhost/admin/admin.php?menu=2
Line 0
Help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在你的成功方法中添加这个,上面你的警报调用
JS 错误地解释了你的 JSON,添加括号将解决它。更多信息:http://www.bennadel.com/blog/99-JSON-Minor-But-VERY-Important-Detail-Creating-Syntax-Error-Invalid-Label.htm
Add this in your success method above your alert call
JS is interpreting your JSON incorrectly, adding the parenthesis will solve it. More info : http://www.bennadel.com/blog/99-JSON-Minor-But-VERY-Important-Detail-Creating-Syntax-Error-Invalid-Label.htm