Note that there are some explanatory texts on larger screens.

plurals
  1. POcallback function doesn't work when using getJSON function in jQuery
    primarykey
    data
    text
    <p>I am trying to use the getJSON function in jQuery to import some data and trigger a callback function. The callback function doesn't run. However, if I try the same thing with the get function, it works fine. Strangely, it works with the get function even when I pass "json" as the type. Why is this happening? I tested the following file in Firefox 3 and IE 7:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt;&lt;head&gt; &lt;meta http-equiv='Content-Type' content='text/html; charset=UTF-8'&gt; &lt;title&gt;ajax test&lt;/title&gt; &lt;script type="text/javascript" src="/jquery-1.3.2.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="button" id="test1" value="get"&gt; &lt;input type="button" id="test2" value="getJSON"&gt; &lt;input type="button" id="test3" value="get with json type"&gt; &lt;script type="text/javascript"&gt; $("#test1").click(function() { $.get("index.html", function(response) { alert('hi'); //works } ) }); $("#test2").click(function() { $.getJSON("index.html", function(response) { alert('hi'); //doesn't work } ) }); $("#test3").click(function() { $.get("index.html", function(response) { alert('hi'); //works }, "json" ) }); &lt;/script&gt; &lt;/body&gt;&lt;/html&gt; </code></pre> <p>This seems to happen no matter what URL I access, as long as it's on the same domain. I tried passing some data and that doesn't make a difference.</p> <p>Of course I can work around the problem by using the get function like I did in my 3rd test function, but I am still curious as to why this is happening.</p> <p>I know there is a <a href="https://stackoverflow.com/questions/572991/jquery-getjson-doesnt-trigger-callback">similar question</a> asked here but it didn't answer my question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload