HTTP 500 Error jQuery Ajax with Web service

﹥>﹥吖頭↗ 提交于 2019-12-28 07:02:06

问题


I have two simple projects in a single Visual Studio solution to understand how a jQuery ajax request works. One is a web service and the second one is a project consuming the web service.

You can download the very small project from here. Download Project file

As you can see in the project, Whenever I try to call the Web Service, Internal Server Error 500 is occurring.

In chrome, I can see the following alert (executed by "Error" function of Ajax call)

Please assist me to find the problem..

EDIT:

function btnClick() {
        debugger;
        var txtValue = $('#txtValue');
        var text = txtValue.val();
        //
        //
        $.ajax({
            url: "http://localhost:12000/ExampleJsonWS.asmx/getValue",
            type: "POST",
            dataType: "json",
            data: "{" + txtValue.val() + "}",
            timeout: 30000,
            async: false,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                debugger;
                alert(data);
                return data;
            },
            error: function (result) {
                debugger;
                //alert(e);
                alert(result.status + ' ' + result.statusText);
            }
        });
    }

回答1:


The problem was that its not possible to POST with keeping the web service in different project while a GET can do that. (Explained by Phillip Haydon). If I understand it wrong or someone want to share more about it, then they are welcome :)

For more info you can have a look at this link

The better alternative is to keep a Web service inside the project and call the other Webservice (which is needed) into the Project's web service.




回答2:


I think the problem may be in your call to web service from Example.aspx:

url: "http://localhost:12000/ExampleJsonWS.asmx/getValue",

Try something like this:

url: "/ExampleJsonWS.asmx/getValue",

Also, check this post: NETWORK_ERROR: XMLHttpRequest Exception 101.



来源:https://stackoverflow.com/questions/14101321/http-500-error-jquery-ajax-with-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!