#6142 closed bug (invalid)
$.getJSON doesn't work using anything newer than jquery 1.3.2?
Reported by: | askurat1 | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.4.2 |
Component: | ajax | Version: | 1.4.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
When using jquery 1.3.2 getJSON works fine but if I use anything newer such as 1.4.x it doesn't work. Here is my site: www.acelogisticsllc.com I have attached my javascript below.
Thanks, Tony
Attachments (4)
Change History (21)
Changed 13 years ago by
comment:1 Changed 13 years ago by
Component: | unfiled → ajax |
---|---|
Resolution: | → invalid |
Status: | new → closed |
You need to make sure that your JSON isn't malformed: http://yehudakatz.com/2010/01/15/jquery-1-4-and-malformed-json/
comment:2 Changed 13 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Iv'e tried the fix from the page you provided me but it doesn't work.
comment:3 Changed 13 years ago by
Would you mind indicating where and how you've made the change? Looking at 600 lines of javscript--99% of which have nothing to do with the problem--makes debugging the issue very hard.
Thanks.
comment:4 Changed 13 years ago by
I have attached the code that is not working. It should load in a login form from php file but doesn't with jquery 1.4.x. Look at $.getJSON. Using firebug there is no errors. I says it is loading the php but it won't render it for some reason on the page.
Hope this helps.
Thanks, Tony
comment:5 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
The important part is the JSON file that you're retrieving - if that file is improperly formatted it'll fail and the callback when never be called. Can you provide us with a copy of the JSON file and re-open the issue?
comment:6 Changed 13 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
I added the post file.
comment:7 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Right - your JSON has single quotes in it, instead of double quotes. You might be interested in using a JSON validator: http://www.jsonlint.com/
comment:8 Changed 13 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
I have three required files in my login.post.php file. Do I need to change the single quotes in those as well?
comment:9 Changed 13 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
Yes, every bit of JSON that you're sending to the server needs to be valid JSON. The original post that I linked to is very informative in this respect: http://yehudakatz.com/2010/01/15/jquery-1-4-and-malformed-json/
comment:10 Changed 13 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
I am having trouble converting this line: echo "{\"status\":false, \"message\":'".$acl->form()."'}"; I've tried: echo "{\"status\":false, \"message\":\"".$acl->form()."/"}"; and: echo "{\"status\":false, \"message\":".$acl->form()."}"; but both of these don't work. Only the one with single quotes work. Whats the problem?
Thanks
comment:11 Changed 13 years ago by
sorry first one I tried I typed in wrong it should be: echo "{\"status\":false, \"message\":\"".$acl->form()."\"}";
comment:13 Changed 13 years ago by
Relates to #5966
Seems like the first time the callback fires, but not subsequent calls
comment:14 Changed 13 years ago by
ok, ends up it was my bad
1.4 implements native json parsing where available, but if your json is invalid, it will fail silently
;)
comment:16 Changed 12 years ago by
Priority: | → low |
---|---|
Resolution: | → invalid |
Status: | reopened → closed |
The reason your code is currently not working is because you're passing invalid JSON through. We recommend that you use jsonlint.com to assist with this. If you require any further assistance please see the jQuery forums.
comment:17 Changed 12 years ago by
I'd also like to add, that for anyone running into this problem, you should likely not be generating your json by concatenating variables together. You are leaving yourself open for errors.
In most languages there is either a native Object -> JSON converter. In python there is simpleJSON and in php there is json_encode (for associative arrays). I'd strongly encourage using one of these tools. They _cannot_ output malformed json.
Javascript file