4

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)

enter image description here

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);
            }
        });
    }
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
  • If you are getting a 500 error it means that there is something wrong on the server-side. You can view the request / response in your developer console to make sure that you're sending the right information via jQuery's Ajax. Additionally a little code posted to the question would be better than asking us to download a file with an unknown origin. – Jay Blanchard Dec 31 '12 at 13:00
  • what happens if you hit the endpoint through a normal http request? – parKing Dec 31 '12 at 19:14
  • @JayBlanchard I am not sure what code to keep here, so I added the code in which I am getting error(jquery file). I hope this will do... BTW, I am sure that there is no problem with webservice code bcos it is ready made file. – Mr_Green Jan 02 '13 at 06:08
  • @parKing you mean that if I run the Webservice? If so, then it is working good and even no errors while invoking. – Mr_Green Jan 02 '13 at 06:09
  • Then your call to the web service URL is wrong. – Jay Blanchard Jan 02 '13 at 13:15
  • 1
    @JayBlanchard no it is correct, I got answer.. I forgot to post here. The problem was that its not possible to POST with keeping the webservice in different project while a GET can do that. (Explained by [Phillip Hayden](http://www.philliphaydon.com/)). If I understand it wrong or someone want to share more, then they are welcome :) – Mr_Green Jan 02 '13 at 13:19

2 Answers2

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.

Community
  • 1
  • 1
Mr_Green
  • 40,727
  • 45
  • 159
  • 271
0

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.

Community
  • 1
  • 1
Ana M
  • 100
  • 1
  • 1
  • 8
  • The port numbers of the two projects are different.. I cant do as you mentioned in your post. If I am wrong please make me right :). BTW, I will check the link. – Mr_Green Jan 02 '13 at 05:44