我正在使用ajax進行表單更新。它工作正常,當我在Ajax中使用GET方法,但它會拋出錯誤405方法不允許當我使用Post方法。我在Localhost上測試這個。我已經在localhost中完成了它,它工作正常。順便說一下,我爲此使用了Laravel 5.2。jQuery .ajax()POST請求拋出405(方法不允許)但GET不
這裏是我的ajax代碼。
$('#update-modal').on('click',function(){
$.ajax({
method : "POST",
url : updateURL,
data : { client_id : $('#client_id').val(),
client_name : $('#client_name').val(),
client_business : $('#client_business').val(),
client_ref : $('#client_ref').val(),
gmail_mail : $('#gmail_mail').val(),
gmail_pass : $('#gmail_pass').val(),
client_dob : $('#client_dob').val(),
client_addr : $('#client_addr').val(),
client_no1 : $('#client_no1').val(),
client_no2 : $('#client_no2').val(),
domain_name : $('#domain_name').val(),
domain_p_date : $('#domain_p_date').val(),
domain_reg : $('#domain_reg').val(),
domain_ex_date : $('#domain_ex_date').val(),
domain_acc_email : $('#domain_acc_email').val(),
domain_acc_pass : $('#domain_acc_pass').val()},
_token : token
})
.done(function(msg){
console.log(msg['message']);
});
});
這裏被認爲
<script>
var updateURL = '{{ route('updateDomain') }}';
var token = '{{Session::token()}}';
</script>
這裏內部使用我的劇本是我的路線
Route::post('/updateDomainModal' ,function(\Illuminate\Http\Request $request){
return response()->json(['message'=> $request['client_name']]);
})->name('updateDomain');
當AJAX功能和路線發生改變進去的方法,它打印的客戶名稱在控制檯中傳遞但是,當使用POST方法完成同樣的操作時,它會拋出錯誤這是錯誤的詳細信息
jquery.min.js:2 GET http://localhost:8000/updateDomainModal?client_id=4&client_name=ABCD&client…2+15%3A01%3A40&domain_acc_email=abc123%40gmail.com&domain_acc_pass=123456 405 (Method Not Allowed)
我想用post方法你需要發送數據作爲有效負載而不是查詢參數。在發送前對數據嘗試使用'JSON.Stringify()' –
使用類型:「POST」而不是方法:「POST」 –
@Mir''type''只是方法的別名 – mdziekon