0

I have created simple web application with laravel 5.8. this is my project url http://localhost/test/public/home

web.php

Route::group(['middleware' => ['auth', 'preventBackHistory']], function() {
   Route::get('home', 'HomeController@index')->name('home');
   Route::post('generate_table.data', 'HomeController@generate_table')->name('generate_table.data');
});

I am calling this ajax into home.blade

"ajax": { 
   "url":"{!! route("generate_table.data") !!}",
   "type": "POST",
    "jsonpCallback": 'jsonCallback',
    "dataType": "jsonp"
 }

I haven't any issue with this ajax.it is loading data. If i navigate to http://localhost/test/public/generate_table.data?callback=jsonCallback , i am getting black screen with

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

No message

If user navigate http://localhost/test/public/generate_table.data?callback=jsonCallback How to navigate back to /home?

.env APP_DEBUG=false

Thank you.

2
  • You cannot check post request by calling it via URL, you need postman or Advanced REST client, i would suggest you to download and install these apps to help you work with laravel APIs/Routes. Commented Aug 27, 2019 at 2:47
  • Thank you @Vipertecpro. I am getting records from url. In home page blade file i am calling ajax url. For security purpose i want to navigate to home screen if user visit to ajax url. The application need to return error or home page if url is not in web.php(Route) and ajax url.
    – suba
    Commented Aug 27, 2019 at 5:03

2 Answers 2

1

You can redirect the user when the GET method is used.

// GET method will be redirected to home.
Route::get('generate_table.data', function () {
    return redirect()->to('/');
});

// The POST method will be passed to the controller.
Route::post('generate_table.data', 'HomeController@generate_table')->name('generate_table.data');
0

Add this to your routes:

Route::get('generate_table.data', 'HomeController@index');
3
  • Thank you @piscator. I am getting error after change route. error "Route [generate_table.data] not defined."
    – suba
    Commented Aug 27, 2019 at 4:56
  • @tksuba Did you delete your named POST route? Commented Aug 27, 2019 at 8:53
  • No, I added Route::get('generate_table.data', 'HomeController@index'); Route::post('generate_table.data', 'HomeController@index');
    – suba
    Commented Aug 27, 2019 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.