Reputation: 1267
I tried to connect to to this web service:
but it alert "error" to
This is the script that I used:
var varType;
var varUrl;
var varData;
var varContentType;
var varDataType;
var varProcessData;
function SetValue() {
varType = "POST";
varUrl = "http://www.w3schools.com/webservices/tempconvert.asmx/FahrenheitToCelsius";
varData = '{"Fahrenheit":"230"}';
varContentType = "application/json; charset=utf-8";
varDataType = "json";
varProcessData = true;
CallService();
}
function CallService() {
$.ajax({
type: varType,
url: varUrl,
data: varData,
contentType: varContentType,
dataType: varDataType,
processdata: varProcessData,
success: function (msg) {
ServiceSucceeded(msg);
},
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.statusText);
alert(thrownError);
}
});
}
function ServiceSucceeded(result) {
alert("ServiceSucceeded");
varType = null; varUrl = null; varData = null; varContentType = null; varDataType = null; varProcessData = null;
}
What should I do?
Upvotes: 0
Views: 4227
Reputation: 8444
You have to use dataType: 'jsonp'
when doing cross-domain requests because of the same-origin policy
Upvotes: 1