Reputation: 455
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.
Upvotes: 0
Views: 4075
Reputation: 3243
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.
Upvotes: 0
Reputation: 34581
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.
Upvotes: 2