【发布时间】:2016-11-16 02:18:23
【问题描述】:
我目前正在使用以下代码向我的 laravel API 发出POST 请求...
fetch('http://laravel.dev/content', {
method: 'POST',
mode:'no-cors',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin':'*'
},
body: JSON.stringify({
})
})
.then((response) => {
console.log(response);
});
路线如下...
Route::post('/content', array('middleware' => 'cors', 'uses' => 'Test@save'));
虽然我配置了cors模式,但我实际使用的是no-cors。
我的控制器Test@save 看起来像...
class Test extends Controller
{
public function save()
{
echo "here";
}
}
我正在尝试将字符串 here 发送回获取请求。但是在我的获取请求中,当我执行console.log(response) 时,我得到了以下响应...
Response {type: "opaque", url: "", status: 0, ok: false, statusText: "" ...}
有没有办法使用我的 Laravel 路由发送自定义响应?如果是这样,我该怎么做?
【问题讨论】: