2

I'm new to JQuery and Web Services. My question is (in the following code), why does url: "WebService1.asmx/WebMethod" work through this JQuery code but if I type that URL directly in my browser, it says the path cannot be found? I have to manually click on the "Invoke" button for the service in the browser in order to call the method and then it navigates to WebService1.asmx/WebMethod.

 $(document).ready(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "WebService1.asmx/WebMethod",
            data: "{}",
            dataType: "json",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (errormessage) {
                alert("got an error");
            }
        });
    });
1

2 Answers 2

3

In case of ajax call, you are invoking the url as POST request. Whereas while accessing the url directly in browser, you are invoking the url as GET request. Your service may accept POST request with empty json array as a parameter which is missing while invoking as GET request.

Sign up to request clarification or add additional context in comments.

Comments

2

POST and GET! The service is listening for different HTTP verbs and responding accordingly.

Pressing the Invoke sends a POST message to the service while typing it in the bar sends a GET message to the service.

Change the query with : type: "GET", and you'll see.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.