0

I am trying to call an asmx web service in plain html page. But not getting output. I'm not getting the exact problem. Here is my ajax code that I wrote to call that asmx web service.

function Getdet(Name)
        {
            alert('hellotest');
            $.ajax({
                type: "POST",
                url: "http://192.168.1.20/myservice/service.asmx?HelloWorld", // add web service Name and web service Method Name
                data: "{''}",  //web Service method Parameter Name and ,user Input value which in Name Variable.
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response)
                {
                    alert('abcd1');
                    $("#spnGetdet").html(response.d); //getting the Response from JSON
                },
                failure: function (msg)
                {
                    alert(msg);
                }
        });
    }

Should I have to add anything in the code..?? Please let me know where I am going wrong in this above code.

Ruchir
  • 1,086
  • 4
  • 24
  • 48

1 Answers1

0

ASMX pages are plain old Web Services and the output is (almost) always in XML format, so don't except JSON out of the box.

Plus, they don't work well on different domain call by default, you will need to ensure that the cross domain is correctly handled.

After all this is done, you will then use the call as:

success: function(response) {
    // http://stackoverflow.com/a/1773571/28004
    var xml = parseXml(response),
        json = xml2json(xml);

    $("#spnGetdet").html(json.d);

}
balexandre
  • 73,608
  • 45
  • 233
  • 342