Reputation: 173
I have a webservice
which will return a value. Here my requirement is, I need to call that webservice
from an index.html
page, that page have an html submit button. On that button click I am calling a JavaScript.
From there I want to call the web method. how can I achieve this.
My webservice is "localhost/ws/service.asmx";
and web method is HelloWorld
<input type="button" value="Submit" id="btn_submit" onclick ="return fun()">
function fun() {
// here I want to call the "helloworld" method.
return true;
}
Upvotes: 11
Views: 107821
Reputation: 4463
Use jQuery for performin POST or GET request from your html page like this :
function fun()
{
var data="hello";
$.get("http://localhost/ws/service.asmx/HelloWord", function(response) {
data = response;
}).error(function(){
alert("Sorry could not proceed");
});
return data;
}
OR :
function fun()
{
var data="hello";
$.post('http://localhost/ws/service.asmx/HelloWord',{},function(response)
{ data = response;
}).error(function(){
alert("Sorry could not proceed");
});
return data;
}
Upvotes: 16
Reputation: 1455
You can send ajax request to a webservice
$.ajax({
url: "WebServiceURL",
data: "", //ur data to be sent to server
contentType: "application/json; charset=utf-8",
type: "GET",
success: function (data) {
alert(data);
},
error: function (x, y, z) {
alert(x.responseText +" " +x.status);
}
});
Upvotes: 7