如何在asp.net页面中使用jquery和Ajax调用c#函数? [英] How to call a c# function using jquery and Ajax in asp.net page...?
本文介绍了如何在asp.net页面中使用jquery和Ajax调用c#函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想调用在页面后面的代码中声明的方法,实际上该方法用于重新生成ASP页面中datagrid的数据,我使用c#作为我在语言后面的代码.
这是方法....
I wanted to call a method declared in my code behind page, actually that method is used for refracing the data of datagrid in asp page, i used a c# as my code behind language.
this is the method....
public void search()
{
int id = Convert.ToInt32(txtSearch.Value.ToString());
ds.Clear();
ds = (DataSet)ser.getDataID("SP_SELECT_DATA_FROM_INFO", id);
if (ds.Tables[0].Rows.Count > 0)
{
grdMyGrid.DataSource = ds;
grdMyGrid.DataBind();
}
else
{
Response.Write("No Record Found");
}
}
现在我想使用带有Ajax的jQuery或javascript调用该方法...
我会尝试的,但是它不起作用
now i want to call that method using a jQuery or javascript with Ajax...
i will try this but it is not working
<script type="text/javascript">
$(document).ready(function () {
$("#ser").click(function () {
if (confirm("Are you sure")) {
$.ajax({
type: "POST",
url: "GridDemo.aspx/search",
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: "json",
success: function (msg) {
if (msg.d) {
alert("Sucess");
}
},
error: function () {
alert("Error try again");
}
});
}
});
});
}
</script>
请帮助我....
please help me....
推荐答案
(文档).ready(
(document).ready(function () {
( # ser").click(如果(确认(" )){
("#ser").click(function () { if (confirm("Are you sure")) {
.ajax({ 类型:" , url:" , contentType:" , 数据:" , dataType:" , 成功:功能(msg){ 如果(msg.d){ alert(" ); } }, 错误:功能(){ alert(" ); } }); } }); }); } </script>
.ajax({ type: "POST", url: "GridDemo.aspx/search", contentType: "application/json; charset=utf-8", data: "{}", dataType: "json", success: function (msg) { if (msg.d) { alert("Sucess"); } }, error: function () { alert("Error try again"); } }); } }); }); } </script>
请帮助我....
please help me....
这篇关于如何在asp.net页面中使用jquery和Ajax调用c#函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文