Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery AJAX JSON dataType Conversion
    primarykey
    data
    text
    <p>Hopefully that title isn't <em>too</em> cryptic. What's happening is I have a jQuery AJAX script that I'm trying to use to access an API on a remote server, which returns a JSON response. However, the API returns the JSON as MIME type "text/html" (in the response header) instead of "application/json". It would seem obvious that I simply need to change the returned content type from text to JSON, to make the AJAX call interpret the data correctly.</p> <p>Unfortunately, this is not the case. I have tried this in a multitude of different ways, all of which fail. The closest I've gotten to getting this API call to work is when the debugger tells me "Resource interpreted as Script but transferred with MIME type text/html". And the AJAX call errors out with my debug message that dumps the jqXHR object in JSON format, which tells me: <code>{"readyState":4,"status":200,"statusText":"parsererror"}</code></p> <p>Here is an example of my code (although I have changed the code many various ways, in my attempts at getting it to work, but this version seems to be the closest to correct):</p> <pre><code>$.ajax({ type: 'GET', url: 'http://username:api-key@www.kanbanpad.com/api/v1/projects.json', contentType: 'application/json', dataType: 'jsonp', converters: { 'jsonp': jQuery.parseJSON, }, success: function(data) { alert(data); }, error: function(jqXHR, textStatus, errorThrown) { console.log(JSON.stringify(jqXHR)); console.log(textStatus+': '+errorThrown); } }); </code></pre> <p>If anyone can figure out what I need to do differently to make this work, I will be extremely grateful.</p> <p><strong>It may also be worth noting that if you copy/paste the API URL into a browser address bar and hit go, it gives the proper JSON response with the proper response header ("application/json")</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    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