Dalam antara muka dingo/api bahagian belakang
$api = app('api.router');
$api->version('v1', function ($api) {
$api->get('products','Api\V1\ProductController@index');
});
public function index()
{
return Product::all();
}
Data adalah seperti berikut
{"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!')
Adakah data yang dikembalikan betul?
Data telah disoal bagaimana untuk mengembalikan data yang betul?
Oleh kerana apabila meja depan membuat permintaan, penyemak imbas melaporkan ralat berikut:
Uncaught SyntaxError: Unexpected token :
Ada sesiapa ada bimbingan
Pelayar mengembalikan yang berikut sehingga format jsonp, bukan?
Jika tidak mengikut format jsonp
Kemudian dingo/api
https://github.com/dingo/api/wiki/Creating-API-Endpoints
Cara mencapai API permintaan merentas tapak
token csrf ditutup
Matikan token csrf
http://www.cnblogs.com/HD/p/4555369.html