【发布时间】:2017-05-07 20:54:30
【问题描述】:
我想使用 ajax jquery 将数据发送到 laravel 5.3 中的 Web 服务。我的ajax代码是(这个问题中的URL是一个例子):
$.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.
我必须做什么?
【问题讨论】:
标签: php jquery ajax web-services laravel-5.3