gpt4 book ai didi

php - Ajax 成功后刷新/重新加载页面 - Laravel

转载 作者:可可西里 更新时间:2023-11-01 01:13:12 26 4
gpt4 key购买 nike

在我的 laravel 项目中,我想在 ajax 成功后刷新我的页面,但我的页面会在成功后刷新。我尝试在 Controller 中使用 laravel redirect 进行刷新,但没有用,我也尝试在 ajax 中进行刷新,但什么也没发生?我该怎么做?我该怎么做?

Controller

if(request()->ajax()) {

//do something
return ['success' => 'successfully done'];
return redirect('admin/all')->with('status','Successfully done!');

JS

<script type="text/javascript">

$('#master').on('click', function(e) {
if($(this).is(':checked',true))
{
$(".sub_chk").prop('checked', true);
} else {
$(".sub_chk").prop('checked',false);
}
});

$('.approve_all').on('click', function(e) {

var allVals = [];
$(".sub_chk:checked").each(function() {
allVals.push($(this).attr('data-id'));
});

if(allVals.length <=0)
{
alert("Please select row.");
}

else {



var check = confirm("Are you sure you want to delete this row?");
if(check == true){

var join_selected_values = allVals.join(",");

$.ajax({
url: $(this).data('url'),
type: 'GET',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: 'ids='+join_selected_values,

success: function (data) {
if (data['success'])
{

$("#" + data['tr']).slideUp("slow");
alert(data['success']);
location="/admin/all";


}
else if (data['error'])
{
alert(data['error']);
}
else
{
//alert('Whoops Something went wrong!!');
}
},
error: function (data) {
alert(data.responseText);
}
});
window.location.href="/your/url" ;

$.each(allVals, function( index, value )
{
$('table tr').filter("[data-row-id='" + value + "']").remove();
});
}

}


$('[data-toggle=confirmation]').confirmation({
rootSelector: '[data-toggle=confirmation]',
onConfirm: function (event, element) {
element.trigger('confirm');
}
});

$(document).on('confirm', function (e) {
var ele = e.target;
e.preventDefault();

$.ajax({
url: ele.href,
type: 'GET',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
success: function (data) {
if (data['success'])
{

$("#" + data['tr']).slideUp("slow");
alert(data['success']);
location="/admin/all";

}
else if (data['error']) {
alert(data['error']);
}
else
{
alert('Whoops Something went wrong!!');
}
},
error: function (data) {
alert(data.responseText);
}
});

return false;
});



});

</script>

最佳答案

您需要使用javascript 来刷新页面。您可以使用 location.reload()

 if ( data['success'] ) 
{
alert(data['success']);
location.reload();
}

关于php - Ajax 成功后刷新/重新加载页面 - Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47483380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com