简体   繁体   中英

call soap wsdl using jquery

I have a webservice written in java and exposed using axis2server.I need to call the service using jquery.My UI is hosted in same machine but in different port(8080). I tried the following code

$('#submit').click(function (event) {
    alert("success");
    var soapmessage = "<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' " + " xmlns:iris='http://iris.ramco.com'>";
    soapmessage += "<soap:Header/>";
    soapmessage += "<soap:Body>";
    soapmessage += "<iris:authenticateUser>";
    soapmessage += "<inputjson>                {username:'admin',password:'admin12*'}</inputjson>";
    soapmessage += "</iris:authenticateUser>";
    soapmessage += "</soap:Body>";
    soapmessage += "</soap:Envelope>";
    alert(soapmessage);
    $.ajax({
        type: 'Post',
        url: 'http://localhost:8090/axis2/services/CiRISService',
        data: soapmessage,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            alert(data);
        },
        error: function (data) {
            alert("eror" + data.d);
        }
    });
    alert("Form Submitted");
});

But i get undefined error.Thanks in advance.

Why don't you use a SOAP client library? For example, there's a jQuery plugin: http://archive.plugins.jquery.com/project/jqSOAPClient

And remember, you're never supposed to call SOAP methods directly, without specialized libraries. There are too many pitfalls you wouldn't expect.

You are using content type "application/json; charset=utf-8" (and data type "json" ) for a soap request. Instead try these

contentType: "text/xml; charset=utf-8"

dataType: "xml"

Edit: I agree with Shedal though, use a library.

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