0

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: 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

asked Jun 30, 2010 at 18:40
3
  • If there is something wrong in parsing your response as json, this problem may happen. Check if your response is coming as a valid json or not... Commented Jun 30, 2010 at 18:44
  • i've checked allready, it comes in {name:"name",val:"value"} format. but even it comes in wrong format, i think it must make an alert? Commented Jun 30, 2010 at 18:45
  • It is expecting a json object to be returned, if it isnt json, its not going to trigger when you explicitly state it should be json. People are willing/trying to help you with this, but need more information to do so. Commented Jun 30, 2010 at 19:14

2 Answers 2

3

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.

answered Jun 30, 2010 at 19:37
Sign up to request clarification or add additional context in comments.

Comments

3

{name: "name", val: "value" } is not valid JSON. The keys must also be strings.

{"name": "name", "val": "value"}
answered Jun 30, 2010 at 19:31

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.