I am learning react js and trying to parse ajax response. So, I have created some sample API using laravel which returns result in json format. Then I try to catch those data using react js. An example API:
Route::get('names', function()
{
$arr = array(
1 => "John",
2 => "Mary",
3 => "Steven"
);
return Response::json($arr);
});
When I try the in browser, it gives me result:
{"1":"John","2":"Mary","3":"Steven"}
But when I try to parse via react, it gives me the following error in console:
The react code for ajax call:
getInitialState: function() {
return {
data: [], value: {}, showOutput: false
}
},
componentDidMount: function() {
$.get("http://ift.tt/2iLihls", function(result) {
this.setState({
data: result
});
}.bind(this));
},
If I try this url:http://ift.tt/2j68GDs
, it works well. So, could tell me, how to make API in laravel which returns json data in similar of url:http://ift.tt/2j68GDs
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iLpq5d
via IFTTT
Aucun commentaire:
Enregistrer un commentaire