我想通過pjax提交表單,提交後我想刷新表格,但在提交表單並嘗試重新加載($.pjax.reload({container:'#products-table'});
)後,jquery腳本不再工作。即使我添加了pjax:success
,但是如果我不重新加載表格,所有腳本都在工作併發送請求,然後我必須手動重新加載以查看更改。或者我已經嘗試提交沒有pjax的表單,頁面由Yii重新加載,然後再次使用腳本。請您的反饋。由於Yii2 pjax reload
$(document).on('ready pjax:success', function(){
$("form.products-input-style").on('beforeSubmit', function(e){
var form = $(this);
$.ajax({
type : "POST",
url: form.attr('action'),
data: new FormData(this),
processData: false,
contentType: false,
success : function(response) {
$.pjax.reload({container:'#products-table'});
$.notify({
icon: "pe-7s-check",
message: "Product is updated."
},{
type: type[2],
timer: 10,
placement: {
from: 'top',
align: 'right'
}
});
},
error : function(response){
console.log(response);
$.notify({
icon: "pe-7s-close-circle",
message: "Error! " + response
},{
type: type[4],
timer: 10,
placement: {
from: 'top',
align: 'right'
}
});
}
});
return false;
}).on('submit', function(e){
e.preventDefault();
});
});