【发布时间】:2021-02-15 09:19:24
【问题描述】:
太棒了, 在 laravel 上使用 ajax 时出现一些错误,控制台返回 404, 那是我的ajax
$('#btn_search_postcode').click(function(e){
let postcode = $('#postcode').val();
if(postcode != ""){
$.ajax({
method: "GET",
url: "{{route('company.postcode')}}",
dataType: "JSON",
data:{
'id':postcode
},
success: function(result){
if(result != ""){
console.log(result.prefectureid);
}
else{
console.log('null');
}
}
})
}
})
我已将 url 更改为 "{{url('company/postcode')}}/"+postcode 但仍然错误 这是我的路线
Route::GET('/company/postcode/{id}', 'mycontroller\companyController@getPostCode')->name('company.postcode');
但是当我将网址更改为时代码工作正常
url: "http://localhost/mylaravel/public/company/postcode/"+postcode,
我不能使用最后一种方法,因为在其他电脑上使用不同的端口。
有人可以帮我解决这个问题吗? 注意:我可以看到 csrf 令牌,当我在 ajax 中再次添加 csrf 令牌时,我在错误链接上看到 2 个令牌
编辑:
我仍然没有解决这个问题,但现在我使用url:rootUrl+"/companies/postcode/"+postcode, 来解决这个问题,这样可以吗?
【问题讨论】: