Calling a webservice through jquery cross domain

你离开我真会死。 提交于 2019-12-12 20:35:41

问题


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();
    }

回答1:


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.



来源:https://stackoverflow.com/questions/2793836/calling-a-webservice-through-jquery-cross-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!