如何从HTML页面调用web服务方法[javascript]无刷新页面 [英] How to call a webservice method from an html page [javascript] with out refresh the page
本文介绍了如何从HTML页面调用web服务方法[javascript]无刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个将返回值的web服务。这里我的要求是,我需要从index.html页面调用webserive,该页面有一个html提交按钮。在那个按钮上点击我打电话给一个javascript。从那里我想打电话给网络方法。我怎么能做到这一点。
I have a webservice which will return a value . Here my requirement is, I need to call that webserive from an index.html page , that page have a 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.
我的webservice是localhost / ws / service.asmx;和webmethod是HelloWorld
My webservice is "localhost/ws/service.asmx"; and webmethod 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;
}
推荐答案
使用jQuery for performin POST或GET请求如下所示:
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:
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;
}
这篇关于如何从HTML页面调用web服务方法[javascript]无刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文