【发布时间】:2021-02-14 16:21:52
【问题描述】:
当 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);
我需要做什么?
【问题讨论】:
-
你在 javascript 中使用刀片?
-
@RokSprogar 是的,它大部分时间都运行良好。
-
您可以将发送到前端的路由 {{route('index', $link->id)}} 输出为字符串(然后表示将执行的javascript的一部分在浏览器中)...但是你不能输出重定向,因为这是一个 laravel/blade/server 函数(并且不在 fe/javascript 上执行)
标签: php ajax laravel redirect csrf