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
Add this in your success method above your alert call
data = eval("(" + data + ")");
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
精彩评论