我正在尝试重新加载div
已通过 AJAX 动态创建的数据,但出现 403 禁止错误。也许我正在做的事情有问题。请你介意帮助我。提前致谢。
HTML:
<div id="curr-elem">
<div class="box-header">
<h3>Elementary Subject</h3>
</div>
<div id="curr-elem-content">
<table id="curr-elem-tble">
</table>
</div>
</div>
jQuery:
var html;
$.ajax({
type: 'POST',
url: 'add_subject.php',
dataType: 'json',
data: { 'func_numbr':'2' },
success: function(data) {
var activator;
var disabler;
var counter_sub = 0 ;
$.each(data, function(i, item) {
if (data[i].subj_status == "0") {
classToAddInactve = "inactiveButton";
DisableInactve = "disabled=\"disabled\""
classToAddActve = "";
DisableActve = ""
}
else {
classToAddInactve = ""
DisableInactve = ""
classToAddActve = "inactiveButton";
DisableActve = "disabled=\"disabled\""
}
html = "<tr>";
html += "<td><lable>Subject: </label><input type='text' name='subject[" + counter_sub + "]' rel='" + data[i].subj_id + "' value='" + data[i].subj_name + "' readonly='readonly'></td>";
html += "<td><input type='button' rel='#loading-window' id='activate[" + counter_sub + "]' name='active' class='button active modal2 " + classToAddActve + "' value='Apply' " + DisableActve + "> ";
html += "<input type='button' rel='#loading-window' id='inactivate["+counter_sub+"]' name='active' class='button inactive modal2 " + classToAddInactve + "' value='Remove from list' " + DisableInactve + "></td>";
html += "</tr>";
$('#curr-elem-tble').append(html);
counter_sub = counter_sub +1;
});
}
});
触发div
刷新的JS:
$('.active').live('click', function() {
var prev = $(this).parent().prev().find('input[type=text]');
var valText = $(prev).val();
var relVal = $(this).parent().prev().find('input[type=text]').attr('rel');
var div = $(this).parent().parent().parent().parent().parent().attr('id');
$("[id*="+div+"]").hide();
$.ajax({
type: 'POST',
url: 'add_subject.php',
dataType: 'json',
data: {
'func_numbr': '7',
'subjct_name': valText,
'subjct_id': relVal
},
success: function(data) {
$('#mask2').hide();
$('#loading-window').hide();
$("[id*=" + div + "]").load("[id*=" + div + "]");
}
});
});