我想用ajax jquery將數據發送到laravel 5.3中的Web服務。我的Ajax代碼是(URL在這個問題就是一個例子):將數據從laravel 5.3發送到使用ajax jquery的web服務
$.ajax({
type: "POST",
url: "http://199.166.212.50:8080/.../add",
contentType:'application/json',
data: {
"requester":
{
"userName": "jac",
"password": "111"
},
"request":
{
"userName":userName,
"password":password,
"firstName": firstName,
"lastName": lastName,
"homeLocationLatLong":
{
"latitude": homeLocationLatLong_latitude,
"longitude": homeLocationLatLong_longitude
},
"homeLocationText": homeLocationText,
"homePhoneNumber": homePhoneNumber,
"cellPhoneNumber": cellPhoneNumber
}
},
dataType: "json",
success: function (result) {
console.log(result);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
但是當我發送數據時,我看到這個錯誤:
XMLHttpRequest cannot load http://199.166.212.50:8080/.../add. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access.
我該怎麼辦呢?
[jQuery的AJAX跨域]的可能的複製(http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain) –