Here John provided a short example for Webservice call from client side. ie., jQuery
Here, I gave simple example to call webservice webmethod from HTML page using jQuery.
The example shows, to get the content from webservice in every 1 minute.
Use of setTimeout()
Copy the code and paste it in your script file.
$(document).ready(function () {
//ReloadPage();
setTimeout("ReloadPage()", 10000);
});
function ReloadPage() {
var profileID = 10;
CallWebMethod(profileID);
setTimeout("ReloadPage()", 10000);
};
Ajax to call Webmethod with Parameter:
function CallWebMethod(id) {
$.ajax({
type: "POST",
url: "http://192.158.2.175/WebService/ws/dataservice.asmx/GetProfileDataByID",
data: "{'profileID' : " + id + "}",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
async: true,
success: function (data) {
var responseJson = JSON.parse(JSON.stringify(data.d));
alert(responseJson );
},
error: function (e) {
alert(e.responseText);
}
});
}
Ajax to call Webmethod without Parameter:
function CallWebMethod() {
$.ajax({
type: "POST",
url: "http://192.158.2.175/WebService/ws/dataservice.asmx/GetAllProfileData",
data: {},
dataType: 'json',
contentType: 'application/json; charset=utf-8',
async: true,
success: function (data) {
var responseJson = JSON.parse(JSON.stringify(data.d));
alert(responseJson );
},
error: function (e) {
alert(e.responseText);
}
});
}
Here, I have showed simple example for webservice call from javascript. Hope it helps for you. Thanks