Bug Tracker

Modify

Ticket #6142 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

$.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:
Blocking: Blocked by:

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

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

Change History

Changed 3 years ago by askurat1

Javascript file

comment:1 Changed 3 years ago by john

  • Status changed from new to closed
  • Resolution set to invalid
  • Component changed from unfiled to ajax

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

Changed 3 years ago by askurat1

Change

comment:2 Changed 3 years ago by askurat1

  • Status changed from closed to reopened
  • Resolution invalid deleted

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

comment:3 Changed 3 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 3 years ago by askurat1

problem code

comment:4 Changed 3 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 3 years ago by john

  • Status changed from reopened to closed
  • Resolution set to invalid

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

JSON post file

comment:6 Changed 3 years ago by askurat1

  • Status changed from closed to reopened
  • Resolution invalid deleted

I added the post file.

comment:7 Changed 3 years ago by john

  • Status changed from reopened to closed
  • Resolution set to invalid

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

  • Status changed from closed to reopened
  • Resolution invalid deleted

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

  • Status changed from reopened to closed
  • Resolution set to invalid

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

  • Status changed from closed to reopened
  • Resolution invalid deleted

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

Anybody have an idea?

comment:13 Changed 3 years ago by patate

Relates to #5966

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

comment:14 Changed 3 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 3 years ago by askurat1

Ok So what is the fix here?

comment:16 Changed 3 years ago by addyosmani

  • Priority set to low
  • Status changed from reopened to closed
  • Resolution set to invalid

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 3 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.