Side navigation
#6142 closed bug (invalid)
Opened February 21, 2010 08:11PM UTC
Closed November 10, 2010 08:04PM UTC
Last modified November 10, 2010 08:12PM UTC
$.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 (17)
Changed February 22, 2010 02:45AM UTC by comment:1
component: | unfiled → ajax |
---|---|
resolution: | → invalid |
status: | new → closed |
Changed February 22, 2010 04:04PM UTC by comment:2
resolution: | invalid |
---|---|
status: | closed → reopened |
Iv'e tried the fix from the page you provided me but it doesn't work.
Changed February 22, 2010 05:57PM UTC by comment:3
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 February 22, 2010 06:33PM UTC by comment:4
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
Changed February 22, 2010 07:16PM UTC by comment:5
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?
Changed February 22, 2010 07:51PM UTC by comment:6
resolution: | invalid |
---|---|
status: | closed → reopened |
I added the post file.
Changed February 22, 2010 07:58PM UTC by comment:7
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:
Changed February 22, 2010 08:12PM UTC by comment:8
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?
Changed February 22, 2010 08:17PM UTC by comment:9
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/
Changed February 23, 2010 04:33PM UTC by comment:10
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
Changed February 23, 2010 04:35PM UTC by comment:11
sorry first one I tried I typed in wrong it should be: echo "{\\"status\\":false, \\"message\\":\\"".$acl->form()."\\"}";
Changed March 01, 2010 05:37PM UTC by comment:12
Anybody have an idea?
Changed April 05, 2010 03:05PM UTC by comment:13
Relates to #5966
Seems like the first time the callback fires, but not subsequent calls
Changed April 08, 2010 12:36AM UTC by comment:14
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
;)
Changed May 21, 2010 05:54PM UTC by comment:15
Ok So what is the fix here?
Changed November 10, 2010 08:04PM UTC by comment:16
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.
Changed November 10, 2010 08:12PM UTC by comment:17
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.
You need to make sure that your JSON isn't malformed:
http://yehudakatz.com/2010/01/15/jquery-1-4-and-malformed-json/