[英]Jquery .load firing twice, but being called once
I have a problem here, my jquery .load function seems to be running twice even though Im only calling it once. 我有一个问题,我的jquery .load函数似乎运行了两次,即使我只调用它一次。 Here is my code:
这是我的代码:
function updateRowItem(idIn){
if (ready) {
id = idIn
$("#controlPanelResult").css("background-color", "");
var query = {};
var tid = id.replace("@", "\\@");
tid = tid.replace(".", "\\.");
var value = $('#'+tid).text();
//var value = decodeURI(document.getElementById(id).innerHTML);
//if (value == "<br>"){
// value = "NULL"
//}
//value = value.replace(" "," ")
//value = value.replace("&","&")
var split = id.split('@');
var temp = split[0];
var uuid = split[1];
var temp2 = temp.split('.');
var tableName = temp2[0];
var item = temp2[1];
query['table_name'] = tableName;
query['uuid'] = uuid;
query[item] = value;
var tid = id.replace("@", "\\@");
tid = tid.replace(".", "\\.");
$.ajax({
async: false,
type: "POST",
//url: '/admin/updateRow?table_name=' + tableName + "&uuid=" + uuid +"&" + item + "=" + value,
url: '/admin/updateRow',
data: query,
success: function(data) {
if (data == "1"){
alert ("Hellooo!")//This alert only and always pops up once
$('#'+tid).empty().load(showRowsUrl + " #" + tid,function (status) {
alert (status) // This alert pops up first once, then twice, then four times, then eight etc....
$("#"+tid).animate({backgroundColor: '#70DB70'}, 'slow');
$('#controlPanelResult').html("Updated: " + id);
$("#controlPanelResult").animate({ backgroundColor: '#70DB70'}, 'slow');
$("#"+tid).animate({backgroundColor: 'white'}, 'slow');
});
} else {
$('#mainRows').load(showRowsUrl, function() {
$("#"+tid).animate({backgroundColor: 'red'}, 'fast');
$('#controlPanelResult').html(data);
$("#controlPanelResult").animate({backgroundColor: 'red'}, 'fast');
});
}
}
});
}
}
This causes my divs contents to be constantly repeated, I would appreciate any help in figuring this out 这导致我的div内容不断重复,我将不胜感激任何帮助
Replace the problematic .load()
call with this: 用以下代码替换有问题的
.load()
调用:
$.get(showRowsUrl, function(data) {
$('#'+tid).replaceWith($('#'+tid,'<div>'+data+'</div>'));
$("#"+tid).animate({backgroundColor: '#70DB70'}, 'slow');
$('#controlPanelResult').html("Updated: " + id);
$("#controlPanelResult").animate({ backgroundColor: '#70DB70'}, 'slow');
$("#"+tid).animate({backgroundColor: 'white'}, 'slow');
});
Explanation: .load
is loading the element into itself, so there are afterwards two elements with the same ID, nested. 说明:
.load
正在将元素加载到自身中,因此后来有两个具有相同ID的元素嵌套。 Then when you run .load
again, it runs on both elements with that ID, and so on. 然后当你再次运行
.load
时,它会在具有该ID的两个元素上运行,依此类推。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.