Call ASMX Web Service using JQuery in SharePoint

There was query raised in TechNet forums regarding loading the Web Service content in Web part.

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/4dc136e1-7c2c-49ff-bb1b-d81e9037d2f8

I posted below answer for that



Add a Content Editor Web Part and add the below snippet in the source editor.

You have to work on the processResult function for desired presentation of the fetched stock information.

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetQuote xmlns='http://www.webserviceX.NET/'> \
<symbol>MSFT</symbol> \
</GetQuote> \
</soapenv:Body> \
</soapenv:Envelope>";

$.ajax({
url: "http://www.webservicex.net/stockquote.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\"
});
});

function processResult(xData, status) {
var liHtml =$(xData.responseXML.text);
$("#stockUL").append(liHtml);
}
</script>
<ul id="stockUL"/>


Comments

  1. Its really useful. thanks
    but how to format Stock Qoutes..

    ReplyDelete

Post a Comment