简体   繁体   中英

Consuming an ASP.NET web service with jquery/ajax

I have a jquery ajax function that is consuming an ASP.NET xml web service, as shown in the code below.

The code is successful up to a point (ie "DoSomething" does what it is supposed to do) but it does not seem to enter the "success" function (ie the alert does not show).

Why?

    $.ajax({
        type: "POST",
        url: "http://myServer/Service1.asmx/DoSomething",
        data: "FirstName=AN&Surname=Other&EmailAddress=another@somewhere.com",
        dataType: "text",
        success: function (data) {
            alert("test");
        }
    });

i think this the way you should call the method

$.ajax({
    type: 'POST',
    url: "/Service1.asmx/DoSomething",
    data: {FirstName:"AN",Surname:"Other",EmailAddress:"another@somewhere.com"},
    dataType: 'text',
    success: function (data) {
        alert("test");
    }
});

and in the method

[WebMethod]
public void dosomething(string FirstName,string Surname,string EmailAddress)
{

//do process
}

hope this helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM