在我的Cakephp应用程序中,单击一行上的编辑会显示一个模态进行编辑。您编辑并提交它并按预期更新行。现在,如果您再次单击该行进行编辑,则会重定向到编辑控制器,而不是重新启动模式。
示例行:
<td>123 Main Street</td>
<td>Line2 Empty</td>
<td>Beverly Hills</td>
<td>CA</td>
<td>90210</td>
<td>US</td>
<td class="actions">
<a href="/addresses/view_ajax" rel="modal:open">View</a>
<a href="/addresses/edit_ajax/1" id="edit-1" class="ajax edit">Edit</a>
</td>
Ajax / Jquery代码:
$('.ajax').click(function(event) {
event.preventDefault();
ajaxId = $(this).attr('id');
ajaxClass = $(this).attr('class');
$.ajax({
url: this.href,
success: function(html, textStatus, jqXHR) {
if (ajaxClass == "ajax delete") {
var tr = $('#' + ajaxId).closest('tr')
tr.css("background-color", "#FF3700");
tr.fadeOut(400, function() {
tr.remove();
});
return false;
} else {
ajaxModal(ajaxId, html, myBaseUrl, ajaxClass);
}
},
error: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 403) {
window.location.replace("<?= $this->Url->build('/') ?>");
}
}
});
});
function ajaxModal(element, html, myBaseUrl, ajaxClass) {
$(html).appendTo('body').modal();
masks();
$("form").submit(function(e) {
e.preventDefault();
if (validate()) {
event.preventDefault();
} else {
$.ajax({
url: $('#' + element).attr('href'),
type: 'POST',
data: $("form").serialize(),
success: function(newHTML, textStatus, jqXHR) {
$.modal.close();
//console.log(ajaxClass);
if (ajaxClass == "ajax edit") {
$('#' + element).closest('tr').empty().append(newHTML);
} else {
console.log('here');
//$('#' + element).closest('table').after("<tr>" + newHTML + "</tr>");
}
},
error: function(jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 403) {
window.location.replace(myBaseUrl + "login");
}
if (jqXHR.status == 400) {
edit(element, jqXHR.responseText);
}
}
});
}
});
我错过了什么会导致这种情况?