I am sending a request from my react app localhost:8080
to my lumen api localhost:8000
to retrieve json data.
This is my routes.php
in lumen: $app->get('list', 'ArticleController@listAll');
And this is my ArticleController.php
in lumen:
<?php
namespace App\Http\Controllers;
use Response;
use Illuminate\Support\Facades\Input;
use App\Article as Article;
class ArticleController extends Controller
{
public function listAll(){
$articles = Article::all();
return response()
->json($articles)
->setCallback(Input::get('callback'));
}
}
Because I get that error for cross domain fetch, I am trying to use jsonp, but for some reason it's still not working.
This is my code in React:
componentWillMount(){
fetch('http://localhost:8000/list?callback=asdf', {
method: 'GET'
}).then(function(res) {
console.log(res);
}).catch(function(err) {
console.log(err);
})
}
Any help would be appreciated. I'm very new to this kind of stuff. Thanks