简体   繁体   中英

How do I call a specific web service method with AJAX?

How do I call a specific WSDL method via ajax.. I have the following service:

http://newsite.wrapcompliance.org/FactoriesWS.wsdl

and I'm trying to call the method factCountByCountryID() , which returns an integer when given a 3 character string. Code so far is as follows:

<h3>jQuery Test</h3>

<script type="text/javascript">

function callService()
{
$.ajax
({
    url: "http://newsite.wrapcompliance.org/FactoriesWS.wsdl",
    type: "POST",
    dataType: "html",
    data: {"countryCd":"BGD"},
    success: processData,
    error: onError
});

return false;
}

function processData(xml)
{
    alert(xml);
}

function onError(request, status, error)
{
alert("It didn't work!!!");
}

</script>

<form method="post" action="">
    <input type="button" value="Do it now!!" onclick="callService(); return false"/>
    </form>

First of all you have the wrong address! WSDL only describes a service, it's not the service implementation itself. If you do like this, you will point your reqest on a file, nothing more. Altough there's a service description in wsdl: " http://apollov-dev.worlddata.com:8080/WrapSystem/services/FactoriesWS "

In addtion, you have to send a valid SOAP message, what will be consumed on the server side. [described in your WSDL]

Some kind of tutorial: http://openlandscape.net/2009/09/25/call-soap-xm-web-services-with-jquery-ajax/

Use jQuery.soap plugin which will handle the SOAP part for you. You need to configure it first and than you can use:

$.soap({
    method: 'factCountByCountryID',
    params: {
        countryCd: 'BGD',
    },
    success: function (data) {
        // do stuff with data
    }
});

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