我试图在普通的html页面中调用asmx Web服务。但没有得到输出。我没有得到确切的问题。这是我编写的用于调用asmx web服务的ajax代码。
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);
}
});
}
我是否必须在代码中添加任何内容.. ??请在上面的代码中告诉我出错的地方。
答案 0 :(得分:0)
ASMX页面是普通的旧Web服务,输出(几乎)始终采用 XML格式,因此除了开箱即用的JSON之外,不要这样做。
另外,默认情况下,它们在不同的域名调用中效果不佳,您需要确保正确处理cross domain。
完成所有这些操作后,您将使用以下呼叫:
success: function(response) {
// http://stackoverflow.com/a/1773571/28004
var xml = parseXml(response),
json = xml2json(xml);
$("#spnGetdet").html(json.d);
}