Reputation: 33
I'm trying to call web service using jQuery and I read a lot of examples, but unfortunately I can't make it work.
I'm trying to call this web service for my exercise : http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit
This is my code below, but no matter what I do, I receive errors 500 (Internal Server Error) or 400 Bad request.
function GetIt(){
var divToBeWorkedOn = "#AjaxPlaceHolder";
var webMethod = "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit?callback=?";
var parameters = 'POST /webservices/tempconvert.asmx/CelsiusToFahrenheit HTTP/1.1 Host: www.w3schools.com Content-Type: application/x-www-form-urlencoded Content-Length: 9 Celsius=5';
//var parameters = 'Celsius=5';
//var parameters = '<Celsius>5</Celsius>';
$.ajax({
type: "POST",
url: webMethod,
data: parameters,
contentType: "text/xml; charset=utf-8",//"application/json; charset=utf-8",
dataType: "xml", //"json"
success: function(msg) {
$(divToBeWorkedOn).html(msg.d);
},
error: function(e){
$(divToBeWorkedOn).html("Unavailable");
}
});
}
I'm not sure how I should pass the parameters ...
Can anybody describe where is the problem and make this example work ?
Thanks a lot.
Upvotes: 1
Views: 3932
Reputation: 36551
try this
function GetIt(){
var divToBeWorkedOn = "#AjaxPlaceHolder";
var webMethod = "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit?callback=?";
var parameters = {'Celsius':'5'};
$.ajax({
type: "POST",
url: webMethod,
data: parameters,
contentType: "text/xml; charset=utf-8",//"application/json; charset=utf-8",
dataType: "xml", //"json"
success: function(msg) {
$(divToBeWorkedOn).html(msg.d);
},
error: function(e){
$(divToBeWorkedOn).html("Unavailable");
}
});
}
Upvotes: 0