出错代码:
$.ajax({
type: "GET",
url: 'firstRequest.json?id=' + $(this).val(),
async: false,
dataType: "json",
success: function(data){
if(data.deleteable == "true"){
$.ajax({
type: "GET",
url: 'secondRequest.json?id=' + $(this).val(),
async: false,
dataType: "json",
success: function(data){
if(data.result=="success"){
alert("删除成功");
reloadPage();
}else{
alert("删除失败");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("请求失败!");
}
});
}else{
alert("无法删除!!!");
return false;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("请求失败!");
}
});
修改之后代码
var clicked = this;
$.ajax({
type: "GET",
url: 'firstRequest.json?id=' + $(clicked).val(),
async: false,
dataType: "json",
success: function(data){
if(data.deleteable == "true"){
$.ajax({
type: "GET",
url: 'secondRequest.json?id=' + $(clicked).val(),
async: false,
dataType: "json",
success: function(data){
if(data.result=="success"){
alert("删除成功");
reloadPage();
}else{
alert("删除失败");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("请求失败!");
}
});
}else{
alert("无法删除!!!");
return false;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("请求失败!");
}
});