I have a script that executes on the click of a button. it is working fine. There are two points where i would like to run delete query to delete db entry
我有一个脚本,只需单击一个按钮即可执行。它工作正常。有两点我想运行删除查询来删除数据库条目
1) I have a code in the script that puts a check if the user has reloaded or pressed back button. the code is:
1)我在脚本中有一个代码,用于检查用户是否已重新加载或按下后退按钮。代码是:
window.onbeforeunload = function(e)
{
return 'You will loose a chance of negotiation for today. Are you sure you want to exit? ';
/***Run delete query for deleting db entry***/
};
If the user reloads or goes to previous page even after the warning i would like to run delete query
2) i have the following part in my script, want to run delete query at the end
2)我的脚本中有以下部分,想在最后运行删除查询
var ticker = function() {
counter--;
var t = (counter / 60) | 0; // it is round off
digits.eq(0).text(t);
t = ((counter % 60) / 10) | 0;
digits.eq(2).text(t);
t = (counter % 60) % 10;
digits.eq(3).text(t);
if (!counter) {
clearInterval(timer);
alert('Time out !');
resetView();
}
};
Problem is that i am not sure how should i write my sql query within my script without letting the user know(query will run at backend). delete query would be something like this
问题是我不知道如何在不让用户知道的情况下在我的脚本中编写我的sql查询(查询将在后端运行)。删除查询将是这样的
$sql="DELETE FROM product where id='".$id."'";
if(!mysqli_query($con,$sql))
{
"Error deleting record:" . mysqli_error($con);
}
can anyone tell how can i combine the codes
任何人都可以告诉我如何组合代码
my ajax code that i tried to use
我尝试使用的ajax代码
window.onbeforeunload = function(e)
{
$.ajax({
type: 'post',
url: 'test2.php',
dataType: 'json',
data: {
txt: txtbox,
hidden: hiddenTxt
},
cache: false,
console.log(returndata);
},
error: function() {
console.error('Failed to process ajax !');
}
});
};
1 个解决方案
#1
0
You should use AJAX for that. Have a look at jQuery's ajax documentation, it should get you started.
你应该使用AJAX。看看jQuery的ajax文档,它应该让你入门。
#1
0
You should use AJAX for that. Have a look at jQuery's ajax documentation, it should get you started.
你应该使用AJAX。看看jQuery的ajax文档,它应该让你入门。