【发布时间】:2021-11-16 13:17:43
【问题描述】:
我有一个 laravel 项目。每个视图页面都位于单独的 js 文件中。问题是我无法从 ajax post 访问路由功能或在在线服务器(数字海洋)中接听电话。 错误是:
Failed to load resource: the server responded with a status of 404 (Not Found)
相同的应用程序在我的本地系统中运行良好。 当我在设计(blade.php)页面中添加 ajax 函数时,它在服务器中工作正常。在设计中改变我所有的功能并不是那么令人愉快。 直到昨天,服务器和应用程序都运行良好。我对设计进行了一些更改,并将其从 bitbucket 拉到了今天的服务器上。之后发生了这个错误。 从 bitbucket 中提取后,我必须在服务器上做些什么吗?我只提取了对设计所做的更改。
我的路由功能:
Route::prefix('invoice_vno_bind')->group(function () {
Route::get('/', 'InvoiceController@getnextvno')->name('invoice_vno_bind');
});
AJAX 函数:
$.ajax({
type: "GET",
url: "invoice_vno_bind",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){
$('#txtVNo').val(data);
},
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.responseText);
}
});
在线服务器上运行ajax的错误函数。
【问题讨论】:
-
你应该在ajax函数中使用路由方法,比如
url: '{{route('invoice_vno_bind')}}' -
我在我的本地系统中使用相同的代码,它工作正常..@AmitSenjaliya
-
本地和服务器设置不同,因此请确保正确的路由 URL 在 ajax 中传递。
-
直到昨天都运行良好。 @AmitSenjaliya
-
请在服务器
url: '{{route('invoice_vno_bind')}}'上尝试使用route方法,因为服务器可能处于仅考虑完全匹配 URL 的严格模式
标签: javascript php ajax laravel digital-ocean