views:

319

answers:

1

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

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.

Sohnee