I need to make a cross-domain ajax request with ?t=bla
for the server and get the following response if success:
{"success":"yeeee","blaOne":"blabla","blaTwo":"blablabla"}
Same goes for the error, just instead of yeeee
, it's boooo
.
Success will be if the ?t=bla
and fail if the ?t=hm
I did something like this:
$.ajax({
method: "GET",
url: "http://...",
crossDomain: true,
data: {t:'bla'},
dataType: "jsonp"
}).then(function(response){
console.log(JSON.stringify(response));
}).catch(function(error){
console.log(JSON.stringify(error));
})
As a result, I'm getting the Uncaught SyntaxError: Unexpected token :
, but I am able to see the response on a browser's resource file with the yeeee
message! And it's the one of the .catch(function(error)
. If I change the data: {t:'hm'}
- I'm getting the appropriate(boooo
) message, but again, it's the .catch(function(error)
.
Any ideas why is this happens and what I can do about it?
I don't have access to the server.
If there's no way to deal with this and it's a server's issue, how in this case I can access the resulted messages(can I at all?)
UPDATE:
I'm getting the No 'Access-Control-Allow-Origin' header is present on the requested resource is I use JSON instead of JSONP... The status I am getting is 200