开发者

Calling a webservice through jquery cross domain

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").v开发者_StackOverflow中文版al() + "','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();
    }


You should attempt to resolve the error on the service - if the WSDL says that you should be able to POST a request and you are passing the correct request, it shouldn't error and that is for the service provider to fix. It is entirely possible that the error they are returning is related to you sending invalid parameters, so check that your request is spot on before referring to the service provider.

They can look at their error logs, or indeed their event viewer to find the exact error message, which may not be made public for security reasons.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜