解决ajax获取不到按钮的id
bindDelete : function bindDelete(){
$(".delete-btn").click(function(){
window.infoId = $(this).data("id");
console.log(window.infoId);
util.myconfirm("确定要删除该题库么?", function(){
$.ajax({
headers : {
'Accept' : 'application/json',
'Content-Type' : 'application/json'
},
type : "GET",
url : "admin/common/delete-field-" + window.infoId,
success : function(message, tst, jqXHR) {
console.log(message+"/"+tst+"/"+jqXHR);
if (!util.checkSessionOut(jqXHR))
return false;
if (message.result == "success") {
util.success("删除成功", function(){
window.location.reload();
});
} else {
util.error("操作失败请稍后尝试:" + message.result);
}
},
error : function(jqXHR, textStatus) {
util.error("操作失败请稍后尝试");
}
});
});
});
},
这是一段js代码,问题是点击搜索获取到该问题的ID,将id传入到ajax中进行url的拼接,但是
url : "admin/common/delete-field-" +$(this).data("id");这样写是获取不到该按钮的id的,存在跨域的问题,所以解决办法之一就是在确认框之前把id的作用于变大,
window.infoId = $(this).data("id");然后在url中拼接就可以获取到该id了。
,

浙公网安备 33010602011771号