Calling web service via jquery cross domain

I am trying to connect to a .asmx webservice (cross domain) using a client script. Right now I'm having trouble using POST as it blocks and in firebug it gives:

OPTIONS Add (method name) 500 internal server error.

I got around this problem by using GET instead, it works fine without entering any parameters, but gives me problems with the parameters. please see below for the code.

Below is a simple example I'm trying to solve using 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);
            }

        });

      

Web service

[WebMethod, ScriptMethod(UseHttpGet = true, XmlSerializeString = false, ResponseFormat = ResponseFormat.Json)]
    public string Add(int num1, int num2)
    {
        return (num1 + num2).ToString();
    }

      

+2


a source to share


1 answer


You should try to resolve the error in the service - if the WSDL says you should be able to POST the request and you are submitting the correct request, it shouldn't be an error and it is necessary for the service provider. It is possible that the error they return is due to sending invalid parameters, so make sure your request is in place before contacting your service provider.



They can look at their error logs or even their event viewers to find the exact error message that cannot be posted for security reasons.

0


a source







All Articles