I write API to the server. Calling this API with backbone.js ..

Ajax request code ..

var filter = { "type": 'testType', "isDone": 'testIsDone' }; setupAjax: function() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content') } }); } $.ajax({ beforeSend: this.setupAjax(), contentType: 'application/json', dataType: 'json', async: false, data: filter, type: 'post', url: 'http://pr.lar/api/tasks', success: function(res) { console.log(res); }, error: function(res) { console.log(['error', res]) } }); 

Laravel server code 5.2

 use App\Http\Requests; use Illuminate\Http\Request; class PartnerController extends Controller { public function __construct() { $this->middleware('auth'); } public function tasks(Request $request) { return $request; } } 

Router

 Route::auth(); Route::get('/', ['as' => 'index', 'uses' => 'indexController@index']); Route::get('/home', ['as' => 'home', 'uses' => 'HomeController@index']); $api = app('Dingo\Api\Routing\Router'); $api->version('v1', function ($api) { $api->group(['namespace' => 'App\Api\Controllers', 'middleware' => ['web']], function ($api) { $api->get('auth', 'UserController@auth'); $api->get('partners/{searchText}', 'PartnerController@search'); $api->get('partner/{guid}', 'PartnerController@info'); $api->get('tasks', 'PartnerController@tasks'); }); 

});

I get this.

Object {/ api / tasks: ""}

If you pass without the application / json type, a simple post, or get .. I get the same thing. Why is there nothing in the request body?

  • try $ request wrap in return response($request) - Orange_shadow
  • Same thing, I just can't understand why I get an empty request - Mr. Music
  • Are you logged in exactly? What is the status of the answer? - Orange_shadow
  • Well you write as I understand single page app? How did you write the routes? There is nothing there that would intercept your request before? Make logging in the method \Log::info('Зашел в index'); and see if it is there or not in storage / logs / log.txt - Orange_shadow
  • I use dingo api .. He has his own route, but the documentation does not say anything about the incoming request .. - Mr. Music

0