我想通过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();
});
});