ajax onerror code,Ajax请求'onError'处理程序

我的网站上有一项功能:删除不刷新页面。用户只需按下'删除',浏览器就会发送Ajax请求。它会用ID参数加载'delete'脚本。Ajax请求'onError'处理程序

一切正常。但由于数据库的参照完整性,它不是很好。例如,有可能删除一些人居住的街道。

我想升级我的脚本。我想添加一个检查来删除脚本,并且如果某些“人员”连接到“街道”表,则不要让删除数据。点击按钮的

jQuery的处理程序:

$('body').on('click', '.deleteStreet', function()

{

var id = $(this).attr('id');

var hideMe = $(this).parent().parent();

var dataString = 'id=' + id;

if(confirm("Are you sure you want to delete street? It is possible some people living there!"))

{

$.ajax({

type: "GET",

url: "/index.pl?mode=streets&action=delete",

data: dataString,

cache: false,

success: function(e)

{

hideMe.hide();

}

});

return false;

}

});

它无论如何都会调用脚本,现在反正会删除数据。我可以添加一些检查现在删除脚本,它不会删除,但jQuery脚本无论如何将工作,无论如何将隐藏表行(因为请求发送好,没有404等)

1)是否有可能请参阅删除脚本结果并根据它隐藏或不隐藏行?例如,它会返回true或false,js脚本会抓住它并显示关于删除或不删除数据的消息。

2)这个问题是由我的网站结构造成的。在index.pl上有一些开关,并根据查询加载适当的脚本加载(mode=street,然后加载street.pl,mode=user然后加载users.pl等)。因此它会显示在delete.pl脚本之前加载的所有数据,并且不可能检查返回的脚本是真是假。

任何帮助? :) 谢谢!

P.S .:我非常抱歉我的英语不好。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的示例: HTML代码: ```html <!DOCTYPE html> <html> <head> <title>AJAX Table Example</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="script.js"></script> </head> <body> <h1>Employee List</h1> <table id="employeeTable"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Phone</th> </tr> </thead> <tbody> </tbody> </table> </body> </html> ``` JavaScript代码(script.js): ```javascript $(document).ready(function() { getEmployeeList(); // on page load, get the employee list }); function getEmployeeList() { $.ajax({ url: "getEmployeeList.php", // URL of the server-side script to handle the AJAX request method: "GET", dataType: "json", success: function(response) { // on success, populate the table with data var employeeTable = $("#employeeTable tbody"); employeeTable.empty(); // clear any existing rows in the table for (var i = 0; i < response.length; i++) { var row = "<tr>"; row += "<td>" + response[i].id + "</td>"; row += "<td>" + response[i].name + "</td>"; row += "<td>" + response[i].email + "</td>"; row += "<td>" + response[i].phone + "</td>"; row += "</tr>"; employeeTable.append(row); // add the new row to the table } }, error: function(xhr, status, error) { // on error, display an error message alert("Error: " + status + " - " + error); } }); } ``` 以上代码将从服务器获取JSON格式的员工列表数据,并将其显示到HTML表格中。在服务器端,您需要编写一个处理AJAX请求的脚本(在此示例中为`getEmployeeList.php`),该脚本将从数据库中检索数据并将其以JSON格式返回给客户端。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值