我正在使用JSON格式发送表单数据,但发现错误“此路由不支持POST方法。受支持的方法:GET,HEAD”。实际上我正在使用获取酒店的API。为此,通过JSON格式发送请求,但出现错误。
<form class="mt40 mb50" action="#" method="post" id="myForm">
<input type="text" name="searchCity" id="searchCity">
<input type="text" name="searchCityCode" id="searchCityCode">
<input type="text" name="nationality" id="nationality">
<input type="text" name="checkin" id="checkin">
<input type="text" name="checkout" id="checkout">
<select class="form-control" name="adult" id="adult" style="height:40px;">
<option value="">Adult Member</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<button type="submit" class="awe-btn awe-btn-13 pr30 pl30 f16 bold font-hind"
id="find">Find
</button>
</form>
脚本是-
$(document).ready(function(){
$("#find").click(function(){
var searchCity = $("#searchCity").val();
var adults = $("#adults").val();
var checkins = $("#checkin").val();
var checkouts = $("#checkout").val();
var nationality = $('#nationality').val();
// Checking for blank fields.
if (searchCity =='' || adults =='' || checkins =='' || checkouts =='' || nationality =='') {
alert("Please fill all fields...!!!!!!");
}
else {
$.ajax({
url:'https://cdn.grnconnect.com/api/v3/hotels',
type:'GET',
Data: {destination_code: search City, check-in: check-ins, check out: checkouts,client_nationality: nationality, cutoff_time: 5000, more_results: true,
hotel_info: false, rates: "comprehensive",rooms:adults},
success:function(data){
if(data['error'] == '0'){
window.location.href = 'https://cdn.grnconnect.com/api/v3/hotels';
}
},
error:function(e){
alert("error in request");
},
});
}
});
});
答案 0 :(得分:0)
未在此路由的路由文件中指定该路由方法。示例:
Route::post('/hotels', 'HotelController@post')->name('hotel');
答案 1 :(得分:0)