【问题标题】:How to call .asmx web service using plain html page如何使用纯 html 页面调用 .asmx Web 服务
【发布时间】:2014-11-19 05:31:38
【问题描述】:

我正在尝试在纯 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);
                }
        });
    }

我是否必须在代码中添加任何内容..??请让我知道我在上面的代码中哪里出错了。

【问题讨论】:

  • 网络服务托管在哪里?它与您的 html 是否在同一个域中?

标签: html asp.net ajax web-services asmx


【解决方案1】:

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多