在 後台 dingo/api 介面
$api = app('api.router');
$api->version('v1', function ($api) {
$api->get('products','Api\V1\ProductController@index');
});
public function index()
{
return Product::all();
}
資料如下
{"products":[{"id":1,"name":"\u5c0f\u9ec4\u74dc","price":"11.21","sort":0,"status":0,"created_at":"2015-08-03 16:15:07","updated_at":"2015-08-03 16:58:01","b_price":"11.21","no":"001","number":100},{"id":3,"name":"\u897f\u7ea2\u67ff","price":"3.22","sort":0,"status":0,"created_at":"2015-08-03 16:59:34","updated_at":"2015-08-03 16:59:34","b_price":"3.22","no":"003","number":100},{"id":39,"name":"\u4e1d\u74dc","price":"10.00","sort":0,"status":0,"created_at":"2015-08-03 18:30:05","updated_at":"2015-08-03 18:30:05","b_price":"10.00","no":"100","number":1000}]}
$.ajax({
type: 'get',
url: 'http://001.com/api/products',
dataType : 'jsonp',
jsonp:"jsoncallback",
success: function(data){
console.log(data);
},
error: function(){
alert('500 error!')
}
});
alert('500 error!')
回傳的資料有錯嗎?
查詢到資料了 改如何回傳 正確的資料呢 ?
因為前台在請求的時候 瀏覽器報錯了 以下內容:
Uncaught SyntaxError: Unexpected token :
有大神指導一下嗎
瀏覽器傳回如下 直到 jsonp 格式 不對嗎
如果 不符合 jsonp 格式
那麼 dingo/api
https://github.com/dingo/api/wiki/Creating-API-Endpoints
是如何做到 跨站 請求api 的 呢
csrf token關了
#
把csrf token關了
http://www.cnblogs.com/HD/p/4555369.html
雷雷