Calling a webservice through jquery cross domain
Posted
by IanCian
on Stack Overflow
See other posts from Stack Overflow
or by IanCian
Published on 2010-05-08T11:16:30Z
Indexed on
2010/05/08
11:18 UTC
Read the original article
Hit count: 555
hi there, i am new to jquery so please bare with me,
I am trying to connect to a .asmx webservice (cross domain) by means of client-side script now actually i am having problems to use POST since it is being blocked and in firebug is giving me:
OPTIONS Add(method name) 500 internal server error.
I bypassed this problem by using GET instead, it is working fine when not inputting any parameters but is giving me trouble with parameters. please see below for the code.
The following is a simple example I am trying to make work out with the use of parameters.
With Parameters
function CallService() {
$.ajax({
type: "GET",
url: "http://localhost:2968/MyService.asmx/Add",
data: "{'num1':'" + $("#txtValue1").val() + "','num2':'" + $("#txtValue2").val() + "'}",
//contentType: "application/json; charset=utf-8",
dataType: "jsonp",
success: function(data)
{
alert(data.d);
}
});
Webservice
[WebMethod, ScriptMethod(UseHttpGet = true, XmlSerializeString = false, ResponseFormat = ResponseFormat.Json)]
public string Add(int num1, int num2)
{
return (num1 + num2).ToString();
}
© Stack Overflow or respective owner