Bug Tracker

Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#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)

main.js (20.4 KB) - added by askurat1 10 years ago.
Javascript file
main.2.js (24.2 KB) - added by askurat1 10 years ago.
Change
test.js (7.3 KB) - added by askurat1 10 years ago.
problem code
login.post.php (2.1 KB) - added by askurat1 10 years ago.
JSON post file

Download all attachments as: .zip

Change History (21)

Changed 10 years ago by askurat1

Attachment: main.js added

Javascript file

comment:1 Changed 10 years ago by john

Component: unfiledajax
Resolution: invalid
Status: newclosed

You need to make sure that your JSON isn't malformed: http://yehudakatz.com/2010/01/15/jquery-1-4-and-malformed-json/

Changed 10 years ago by askurat1

Attachment: main.2.js added

Change

comment:2 Changed 10 years ago by askurat1

Resolution: invalid
Status: closedreopened

Iv'e tried the fix from the page you provided me but it doesn't work.

comment:3 Changed 10 years ago by miketaylr

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.

Changed 10 years ago by askurat1

Attachment: test.js added

problem code

comment:4 Changed 10 years ago by askurat1

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 10 years ago by john

Resolution: invalid
Status: reopenedclosed

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?

Changed 10 years ago by askurat1

Attachment: login.post.php added

JSON post file

comment:6 Changed 10 years ago by askurat1

Resolution: invalid
Status: closedreopened

I added the post file.

comment:7 Changed 10 years ago by john

Resolution: invalid
Status: reopenedclosed

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 10 years ago by askurat1

Resolution: invalid
Status: closedreopened

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 10 years ago by john

Resolution: invalid
Status: reopenedclosed

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 10 years ago by askurat1

Resolution: invalid
Status: closedreopened

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 10 years ago by askurat1

sorry first one I tried I typed in wrong it should be: echo "{\"status\":false, \"message\":\"".$acl->form()."\"}";

comment:12 Changed 10 years ago by askurat1

Anybody have an idea?

comment:13 Changed 10 years ago by patate

Relates to #5966

Seems like the first time the callback fires, but not subsequent calls

comment:14 Changed 10 years ago by patate

ok, ends up it was my bad

http://www.jsonlint.com/

1.4 implements native json parsing where available, but if your json is invalid, it will fail silently

;)

comment:15 Changed 10 years ago by askurat1

Ok So what is the fix here?

comment:16 Changed 9 years ago by addyosmani

Priority: low
Resolution: invalid
Status: reopenedclosed

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 9 years ago by SlexAxton

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.

Note: See TracTickets for help on using tickets.