Reputation: 216
jquery ajax code
$.ajax( {
cache: false,
crossDomain: true,
headers: {
"contentType": "application/json; charset=utf-8",
},
dataType: 'jsonp',
url: "https://ss.com/rest/v1/users/demo";
type: "GET",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("demo" + ":" + "password"));
},
success: function(data) {
console.log(data);
console.log("done");
},
error: function() {
console.log( "not done" );
}
} );
when i am executing the code in chrome i am getting this error
Uncaught SyntaxError: Unexpected token :
can anyone help me to get out of this error
Upvotes: 1
Views: 74
Reputation: 1073988
That code doesn't have a syntax error, but you've told jQuery that it's a JSONP request, which means it will cause a script
element to get added to the document. If that script
element's src
points to something that returns JSON, not JSONP, you'll get that error. The solution is to ensure that you know what the endpoint you're calling really provides and either don't specify dataType
at all, or specify the correct one.
Upvotes: 2