I stumbled upon this problem while helping another user here at SO, There is a webservice that sends a json formatted output, that when looked into the console seems ok but it triggers a parse error when parsing it directly using getJSON or a similar ajax request:
Unexpected token ':'. Parse error.
While this is weird, it could be solved by just getting the plain text instead, however the server needs a JSONP request (it has no CORS headers). I tried in many ways to prevent jQuery to automatically parse the response to JSON but to no avail. If anybody knows how to either fix the seemingly incorrect parse error or to prevent parsing in the first place, please let me know.
The code I have tried so far is:
var baseUrl = "https://acs.leagueoflegends.com/v1/stats/game/TRLH3/1001440043/timeline?gameHash=4725b07311676885&callback=?";
$.ajax({
url: baseUrl,
dataType: 'json',
crossDomain: true,
processData: false,
converters: {"* text": window.String, "text html": true, "text json": true, "text xml": jQuery.parseXML},
success: function(data){
$('#output').html(data);
},
error:function(jqXHR,status, error){
console.log(jqXHR);
console.log(status);
console.log(error);
$('#output').html(jqXHR);
}
});
Jsfiddle: https://jsfiddle.net/6Lwjpjmo/22/
To make the question more clear:
When I use datatype json
with callback in the url or datatype jsonp
I can see in the console the json response being returned. But it triggers a parse error.
If instead I use datatype text
or anything else I get a cross domain denied error.