How to call Web Service Through SOAP in javascript

Web Service can also be called with Javascript as well. I am explaining this by the use of AJAX.
But the million dollor question is
If Ajax is already there then what is the use of Web Service with Javascript?
Is Web Service is better than general Ajax Call?

The answer of all above question is Web Service is a uniform ,standered and more secure solution then Ajax. Irrespective of normal AJAX based calling where we just hit certain URL with not such a secure medium like a web service does. Because Web Service follows the standered of WSDL this WSDL can easily be shared to another person who wants to be the client irrespective of the technology SOAP client is using. Web Service is more secure, much advance and recommended from W3C.

Example of calling Web Service through SOAP in javascript

<title>Calling Web Service from jQuery</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnCallWebService").click(function (event) {
var wsUrl = "";
var soapRequest ='<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap=""> <soap:Body> <getQuote xmlns:impl=""> <symbol>' + $("#txtName").val() + '</symbol> </getQuote> </soap:Body></soap:Envelope>';
type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: processSuccess,
error: processError


function processSuccess(data, status, req) { alert('success');
if (status == "success")


function processError(data, status, req) {
//alert(req.responseText + " " + status);

Calling Web Services with jQuery/AJAX
Enter your name:
<input id="txtName" type="text" />
<input id="btnCallWebService" value="Call web service" type="button" />
<div id="response" ></div>

Related posts:

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)