使用JQuery/JavaScript在远程机器上调用web服务,而无需更改web服务

Calling a webservice on remote machine with JQuery/JavaScript without changing webservice

本文关键字:服务 web 调用 JavaScript JQuery 程机器 机器 使用      更新时间:2023-09-26

我有一个web服务在我的服务器上运行,但我没有代码来修改它,我只能在它的配置文件中进行更改。

我需要从JQuery/JavaScript调用这个webservice

这是我到目前为止尝试的

<script>
    $(document).ready(function () {
        debugger;
        jQuery.support.cors = true;
        $.ajax({
            type: "GET",
            contenttype: "application/json; charset=utf-8",
            data: "{null}",
            url: "http://example.com:1032/service1.asmx/HelloWorld",
            dataTyp: "json",
            success: function (res) {
                debugger;
                $("#Text1").val(res.text);
            },
            error: function (err) {
                debugger;
                alert(err);
            }
        });
    });
</script>

但是没有成功,它进入错误块。我还在其他机器的浏览器http://example.com:1032/service1.asmx/HelloWorld中尝试了这个url,但它显示The test form is only available for requests from the local machine.

我已经看了相关的问题,但是他们需要改变webservice

是否有任何方式我可以调用服务不改变代码的webservice?

编辑: jquery出错

err = Object {readyState: 4, responseText: "<html>
↵ <head>
↵ <title>Runtime Error</…le>
↵
↵ <br>
↵
↵ </body>
↵</html>
↵", status: 500, statusText: "Internal Server Error"}

EDIT:只是为了补充,我可以从c# ASP调用这个服务方法。在其他机器上运行的网站

哇,添加到我的配置为我工作

<configuration>
    <system.web>
     <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>

我现在可以从浏览器和jquery调用服务,以及上面的方法,从远程机器