[英]Redirect back with errors and input in custom request class : Laravel 5
[英]How to redirect back with errors in Laravel 8 inside an Ajax request
当 data.custom_input === "false" 我想重定向回错误。 redirect()->back() 在控制台中给我这个错误:Uncaught SyntaxError: Unexpected number: cd988e2f-ba9c-4b66-97d9-618e776ae740:157。 这是我传递给所有路线的 uuid。
URL::previous 工作正常,但我不能传递任何错误。
let interval = 1000;
function doAjax() {
$.ajax({
type: 'POST',
url: '/listen/custominput',
data: {
'_token': $('meta[name="csrf-token"]').attr('content')
},
dataType: 'json',
success: function (data) {
if (data.custom_input === "true") {
window.location.href = "{{route('index', $link->id)}}";
} else if (data.custom_input === "false") {
window.location.href = {{redirect()->back()->withErrors(['error', 'has-error'])}};
}
},
complete: function (data) {
setTimeout(doAjax, interval);
}
});
}
setTimeout(doAjax, interval);
我需要做什么?
而不是您的 (POST) 路由返回 custom_input = "false" 然后尝试在 JavaScript 中重定向回来,您应该在 (POST) 路由控制器(而不是刀片/js)中使用您已有的重定向:
redirect()->back()->withErrors(['error', 'has-error'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.