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?
return response($request)- Orange_shadow\Log::info('Зашел в index');and see if it is there or not in storage / logs / log.txt - Orange_shadow