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

允我心安 提交于 2019-12-25 00:38:00

问题


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>


回答1:


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
    }
});



回答2:


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/



来源:https://stackoverflow.com/questions/15527345/how-do-i-call-a-specific-web-service-method-with-ajax

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