我可以使用不带回发功能的客户端回调来连接数据库 [英] Can i used Client Callback without Postback with connect to Database

查看:66
本文介绍了我可以使用不带回发功能的客户端回调来连接数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的项目中,有一个按钮可以将特定主题添加到收藏夹,
当用户按下按钮时,它将连接到数据库并为用户的收藏夹添加特定主题.

但我想做到没有回发,

因此,尽管我需要连接到数据库,但我可以使用客户端回调吗?
如果是的话,该怎么做

否则我必须使用AJAX ??

Hi guys,

In my project, there is button to add specific topic to favorite,
when user press the button it connect to database and add specific topic to favorites for the User.

But i want to do it without postback,

So, can i used Client Callback although i need to connect to database,
if yes how to do that

or i must use AJAX ??

推荐答案

看看下面的链接,其中涵盖了使用"ICallBackEventHadnler"和使用Jquery的Ajax.
简化Asp.Net Core Ajax [
Have a look at below link, which covers use of "ICallBackEventHadnler" and Ajax using Jquery.

Simplifying Asp.Net Core Ajax[^]



您可以为此目的使用ajax,您需要添加Jquery库.
之后,您可以根据需要修改以下代码行.
Hi,
You can use ajax for this purpose you need to add Jquery library.
after it you can modify following code lines according to your requirements.


.ajax({
类型:
"POST",
网址:
"AjaxCalls.aspx?functionName = addfavourite",
数据:
''userID = \''''+ userID +''\''& amp; categoryID =''+ selecttedategoryId,
成功:onSuccsess
});
}
函数onSuccsess(result){
finnd控件ans显示结果
}
并在ajaxcalls.aspx页面上:

在page_load事件中添加此代码
Response.Expires = -1; //需要防止网页在客户端浏览器上被取消缓存
字符串switch_on = Request.QueryString ["functionName"].ToLower();
开关(switch_on)
{
案例"konter":
字符串userID = Request.Form ["userID"];
字符串categoryID = Request.Form ["categoryID"];
//为此数据插入命令
ResponseHandling(数据保存成功");
}


//创建处理ajax响应的函数.
私有void ResponseHandling(字符串结果)
{
Response.Clear(); //清除现有的HTML
Response.ContentType =文本/纯文本"; //更改内容类型
Response.Write(result);//将获取的值发送回调用函数.
Response.End();
}

谢谢
Mahessh K. Sharma
http://www.helpondesk.blogspot.com
.ajax({
type:
"POST",
url:
"AjaxCalls.aspx?functionName=addfavourite",
data:
''userID=\''''+userID+ ''\''&categoryID=''+ selecttedategoryId ,
success: onSuccsess
});
}
function onSuccsess(result) {
finnd control ans show result
}
and on ajaxcalls.aspx page:

Ad this code in page_load event
Response.Expires = -1; //required to keep the page from being un cached on the client''s browser
string switch_on = Request.QueryString["functionName"].ToLower();
switch (switch_on)
{
case "konter":
string userID= Request.Form["userID"];
string categoryID = Request.Form["categoryID"];
//insert command for this data
ResponseHandling("data saved successfully");
}


//Create function which handle ajax response.
private void ResponseHandling(string result)
{
Response.Clear(); //clears the existing HTML
Response.ContentType = "text/plain"; //change content type
Response.Write(result);//Send back the fetched value to calling function.
Response.End();
}

Thanks
Mahessh K. Sharma
http://www.helpondesk.blogspot.com


这篇关于我可以使用不带回发功能的客户端回调来连接数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆