Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery ajax request using jsonp error
    primarykey
    data
    text
    <p>I'm writing an app and I need to access some json data in the client side from another server. Because of the cross domain issue I plan on using jsonp. jQuery allows me to do this using the $.getJSON() method, however, I have no way to tell if the method has failed (i.e., the server is not responding or something). So I tried the approach to get the JSON data using $.ajax instead. But it's not working and I don't know what to try. Here an example showing my issue:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"&gt; &lt;title&gt;TEST&lt;/title&gt; &lt;script type="text/javascript" src="scripts/jquery-1.5.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('#button_detect').click(function(){ var feedApiAjax = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&amp;q='; var feedApiGetJSON = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&amp;callback=?&amp;q='; var feedUrl = 'http://www.engadget.com/rss.xml'; $.ajax({ url: feedApiAjax + feedUrl, datatype: 'jsonp', success: function(data) { console.log('$.ajax() success'); }, error: function(xhr, testStatus, error) { console.log('$.ajax() error'); } }); $.getJSON( feedApiGetJSON + feedUrl, function(data) { console.log('$.getJSON success'); }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="button_detect"&gt;CLICK ME!!!!&lt;/div&gt; &lt;/body&gt; </code></pre> <p></p> <p>If you create a web page with this code and click on the "Click Me" div you'll see that the $.getJSON request is working and the $.Ajax one is not. I've tried putting/removing the "callback=?" tg, used "jsonp" and "json" data types, but non of this worked.</p> <p>Any idea on what might I be doing wrong?</p> <p>Cheers!</p>
    singulars
    1. This table or related slice is empty.
    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