如何在鼠标悬停功能上调用webservices
问题描述:
嗨专家..
我创建了一个Web服务..它正在从数据库中获取数据..现在我必须在鼠标悬停时刷数据..但我无法调用鼠标悬停时的服务
Hi Experts ..
I have created a web services ..which is fetching data from database ..Now I have to shoe data on mouse hover ..but I am not able to call the services on mouse hover
[WebMethod]
public DataSet GetData()
{
if(cn.State==ConnectionState.Closed)
{
cn.Open();
}
SqlDataAdapter da = new SqlDataAdapter("select notes_note,c.cand_fname + ' ' + cand_lname as name, n.notes_createddate,c.cand_id_pk from tb_notes n,tb_candidate_go_beta c where n.notes_about_id=c.cand_id_pk ", cn);
DataSet dt = new DataSet();
da.Fill(dt);
return dt;
cn.Close();
}
现在我在鼠标悬停时调用了这项服务..我怎么做...请帮助
Now i have call this services on mouse hover ..How i can do this ...please help
答
你可以在jquery的帮助下简单地叫你web服务。以下是您的样本系数。
you can simply call you web service with the help of jquery. Here is the sample coe for you.
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
function abc()
{
.ajax({
类型:POST,
contentType:应用/ JSON; charset = utf-8,
url:Webmethod.aspx / BindDataToDropDown,
data:{},
dataType:Json,
success:function(数据){
//当你成功执行web方法时调用这个函数。
//编写从web方法返回的绑定数据的代码。
})
}
});
}
< / script >
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Webmethod.aspx/BindDataToDropDown", data: "{}", dataType: "Json", success: function (data) { // this function is called when you web method executed sucessfully. // write code for binding data returned from web method. }) } }); } </script>
只需调用函数abc( )在鼠标悬停事件的控件上它将调用Web服务。
Just simply call the function "abc()" on mouse hover event of the control it will the call the web service.
<img onmouseover="abc()" border="0" src="smiley.gif" alt="Smiley" width="32" height="32">
>
您好,
添加 jQuery [ ^ ]在您的网页上使用jQuery,您可以在这样:
Hi,
Add jQuery [^] on your page and using jQuery you can acheive this in this way: