I'm making the following call to a webservice:
$.ajax({
dataType:'json',
cache:false,
type: "GET",
url: url,
success: function (data) {
alert("success");
},
error: function (xhr, ajaxOptions, thrownError){
alert('Failed to subscribe.');
}
});
The webservice is hit and definitely returns json - I can hit it via the browser and get what I expect. In my site, the error function is always called.
using Fiddler I can see there is a 200 result - the only thing I notice is that in the response fiddler says
Response is encoded and may require decoding before inspection. Click here to transform.
When I click it, the response goes from being a load of random symbols to being my expected json.
Upon Googling this, I see suggestions of adding contentType: "application/json;charset=UTF-8",
to my call.
This stops my webservice function from being hit at all.
I tried changing it to POST also, just to see if that was the issue...still doesn't work.
Can anyone point out what I', doing wrong?
EDIT: I've just noticed I'm getting this in Chrome
Refused to set unsafe header "Accept-Encoding" XMLHttpRequest cannot load http://localhost:57631/Api/Products/SubscribeEmailMeWhenAvailable/203/wrfw@wrwq.com?_=1447757623275. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:50217' is therefore not allowed access.