look at this function please
$(".menu_tree img.edit").click(function()
{
id = this.id;
lang = '<?=$lang_id?>';
var body_width = $("body").width();
var body_height = $("body").height();
$("#shadow").width(body_width);
$("#shadow").height(body_height);
$("#shadow").show();
var width = $("#edit_title").width();
var height = $("#edit_title").height();
$("#edit_title").height(0);
$("#edit_title").width(0);
$("#edit_title").animate(
{
width: width,
height:开发者_StackOverflow社区 height
},600);
$.post
(
"get_title.php",
{id: id, lang: lang},
function(data)
{
alert("qqq");
},
"json"
);
});
in get_title.php
i generate json object, something like {name:"name",val:"value"}
it works fine if i don't wrote "json"
, but with "json"
it even doesn't alert my qqq
:(
Any ideas?
Thanks
The 1.4.2 parser is more strict than earlier versions. As noted by michal, that json is not valid because the property names are not double quoted. I was bit by this issue recently when upgrading a site to jQuery 1.4.2.
I strongly suggest allowing PHP to take care of json encoding for you. My problem, which I suspect is yours as well, was that I was putting together json strings manually in PHP, and jQuery was rejecting it because some were single quoted.
So, for the PHP rather than something like
echo "{name:'$val',val:'$val'}";
exit;
let PHP do the encoding:
header('Content-type: application/json');
echo json_encode(array('name'=>$val,'val'=>$val));
exit;
also, adding a Content-Type header for JSON can't hurt if you aren't already.
{name: "name", val: "value" }
is not valid JSON. The keys must also be strings.
{"name": "name", "val": "value"}
精彩评论