I hope this name is not too mysterious. What happens, I have a jQuery AJAX script that I am trying to use to access an API on a remote server that returns a JSON response. However, the API returns JSON as the MIME type "text / html" (in the response header) instead of "application / json". It would seem that I just need to change the returned content type from text to JSON in order to force the AJAX call to correctly interpret the data.
Unfortunately, this is not so. I tried this in many different ways, all of which fail. The closest I got to get this API call to work is when the debugger tells me "Resource interpreted as a script, but passed with text like MIME / html". And the AJAX error causes an error with my debug message, which unloads the jqXHR object in JSON format, which tells me: {"readyState":4,"status":200,"statusText":"parsererror"}
Here is an example of my code (although I changed the code in many different ways, trying to make it work, but this version seems to be the closest one):
$.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); } });
If someone can understand what I need to do differently to make this work, I will be extremely grateful.
You can also note that if you copy / paste the API URL into the address bar of the browser and press "go", it gives the correct JSON response with the corresponding response header ("application / json")
jquery types jsonp ajax
therealklanni
source share