Laravel error 405(Method Not Allowed) Ajax Posting2019 Community Moderator Electionlaravel-5 passing variable to JavaScriptjQuery Ajax POST example with PHPDjango CSRF check failing with an Ajax POST requestLaravel 5.2 Ajax POST TokenMismatchException with Valid CSRF TokenLaravel 5.4 null csrf_token() when posting to routeLaravel 500 (Internal Server Error) on Ajax PostMethod not Allowed error on Ajax Post request (500 error) Laravel FrameworkLaravel 5.5 ajax call 419 (unknown status)AJAX post not sending data to controllerajax post return 405 (Method Not Allowed) on Laravel 5.7Method not allowed error 405 post ajax request to post route

Why did it take so long to abandon sail after steamships were demonstrated?

Do I need life insurance if I can cover my own funeral costs?

When do we add an hyphen (-) to a complex adjective word?

Welcoming 2019 Pi day: How to draw the letter π?

Is it possible / allowed to upcast ritual spells?

Science-fiction short story where space navy wanted hospital ships and settlers had guns mounted everywhere

At what level can a dragon innately cast its spells?

I need to drive a 7/16" nut but am unsure how to use the socket I bought for my screwdriver

How could a female member of a species produce eggs unto death?

2D counterpart of std::array in C++17

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?

Be in awe of my brilliance!

Life insurance that covers only simultaneous/dual deaths

Provisioning profile doesn't include the application-identifier and keychain-access-groups entitlements

Have researchers managed to "reverse time"? If so, what does that mean for physics?

Did CPM support custom hardware using device drivers?

Current sense amp + op-amp buffer + ADC: Measuring down to 0 with single supply

What options are left, if Britain cannot decide?

Counting certain elements in lists

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

How is the Swiss post e-voting system supposed to work, and how was it wrong?

Humanity loses the vast majority of its technology, information, and population in the year 2122. How long does it take to rebuild itself?

Rejected in 4th interview round citing insufficient years of experience

Bash: What does "masking return values" mean?



Laravel error 405(Method Not Allowed) Ajax Posting



2019 Community Moderator Electionlaravel-5 passing variable to JavaScriptjQuery Ajax POST example with PHPDjango CSRF check failing with an Ajax POST requestLaravel 5.2 Ajax POST TokenMismatchException with Valid CSRF TokenLaravel 5.4 null csrf_token() when posting to routeLaravel 500 (Internal Server Error) on Ajax PostMethod not Allowed error on Ajax Post request (500 error) Laravel FrameworkLaravel 5.5 ajax call 419 (unknown status)AJAX post not sending data to controllerajax post return 405 (Method Not Allowed) on Laravel 5.7Method not allowed error 405 post ajax request to post route










0















Hello i wnat to send my data with ajax to my controller.



My CODE



AJAX



 $.ajax( 
type:'POST',
header:
'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
,
url:"route('race.post')",
data:
_token: " csrf_token() ",
dataType: 'json',
contentType:'application/json',



)
.done(function()
alert('success');
)
.fail(function()
alert("error");
);


CONTROLLER



 public function Points(Request $request)
$test = $request->input('data');
return "$test";



ROUTE



Route::post('updateC', ['uses' =>'RacesController@Points', 'as' => 'race.post']); 


And there are the errors what i get.



Console



Network-preview



Network-Response










share|improve this question






















  • I think You have separate .js file for ajax. that's why your route and csrf_token is not working.

    – ThataL
    Mar 7 at 9:48











  • That's true i have separetad js file for ajax.

    – Patrik
    Mar 7 at 9:49











  • Thats why it is not working. for csrf_token use meta tag. and for url pass url as parameter to javascript onclick, or Onchange function. can i see your .js fiile when the ajax will call..

    – ThataL
    Mar 7 at 9:52











  • try my answer as below. I have changed the code by comparing previous and current question of you.

    – ThataL
    Mar 7 at 10:05















0















Hello i wnat to send my data with ajax to my controller.



My CODE



AJAX



 $.ajax( 
type:'POST',
header:
'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
,
url:"route('race.post')",
data:
_token: " csrf_token() ",
dataType: 'json',
contentType:'application/json',



)
.done(function()
alert('success');
)
.fail(function()
alert("error");
);


CONTROLLER



 public function Points(Request $request)
$test = $request->input('data');
return "$test";



ROUTE



Route::post('updateC', ['uses' =>'RacesController@Points', 'as' => 'race.post']); 


And there are the errors what i get.



Console



Network-preview



Network-Response










share|improve this question






















  • I think You have separate .js file for ajax. that's why your route and csrf_token is not working.

    – ThataL
    Mar 7 at 9:48











  • That's true i have separetad js file for ajax.

    – Patrik
    Mar 7 at 9:49











  • Thats why it is not working. for csrf_token use meta tag. and for url pass url as parameter to javascript onclick, or Onchange function. can i see your .js fiile when the ajax will call..

    – ThataL
    Mar 7 at 9:52











  • try my answer as below. I have changed the code by comparing previous and current question of you.

    – ThataL
    Mar 7 at 10:05













0












0








0








Hello i wnat to send my data with ajax to my controller.



My CODE



AJAX



 $.ajax( 
type:'POST',
header:
'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
,
url:"route('race.post')",
data:
_token: " csrf_token() ",
dataType: 'json',
contentType:'application/json',



)
.done(function()
alert('success');
)
.fail(function()
alert("error");
);


CONTROLLER



 public function Points(Request $request)
$test = $request->input('data');
return "$test";



ROUTE



Route::post('updateC', ['uses' =>'RacesController@Points', 'as' => 'race.post']); 


And there are the errors what i get.



Console



Network-preview



Network-Response










share|improve this question














Hello i wnat to send my data with ajax to my controller.



My CODE



AJAX



 $.ajax( 
type:'POST',
header:
'X-CSRF-TOKEN':$('meta[name="csrf-token"]').attr('content')
,
url:"route('race.post')",
data:
_token: " csrf_token() ",
dataType: 'json',
contentType:'application/json',



)
.done(function()
alert('success');
)
.fail(function()
alert("error");
);


CONTROLLER



 public function Points(Request $request)
$test = $request->input('data');
return "$test";



ROUTE



Route::post('updateC', ['uses' =>'RacesController@Points', 'as' => 'race.post']); 


And there are the errors what i get.



Console



Network-preview



Network-Response







javascript ajax laravel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 9:13









PatrikPatrik

112




112












  • I think You have separate .js file for ajax. that's why your route and csrf_token is not working.

    – ThataL
    Mar 7 at 9:48











  • That's true i have separetad js file for ajax.

    – Patrik
    Mar 7 at 9:49











  • Thats why it is not working. for csrf_token use meta tag. and for url pass url as parameter to javascript onclick, or Onchange function. can i see your .js fiile when the ajax will call..

    – ThataL
    Mar 7 at 9:52











  • try my answer as below. I have changed the code by comparing previous and current question of you.

    – ThataL
    Mar 7 at 10:05

















  • I think You have separate .js file for ajax. that's why your route and csrf_token is not working.

    – ThataL
    Mar 7 at 9:48











  • That's true i have separetad js file for ajax.

    – Patrik
    Mar 7 at 9:49











  • Thats why it is not working. for csrf_token use meta tag. and for url pass url as parameter to javascript onclick, or Onchange function. can i see your .js fiile when the ajax will call..

    – ThataL
    Mar 7 at 9:52











  • try my answer as below. I have changed the code by comparing previous and current question of you.

    – ThataL
    Mar 7 at 10:05
















I think You have separate .js file for ajax. that's why your route and csrf_token is not working.

– ThataL
Mar 7 at 9:48





I think You have separate .js file for ajax. that's why your route and csrf_token is not working.

– ThataL
Mar 7 at 9:48













That's true i have separetad js file for ajax.

– Patrik
Mar 7 at 9:49





That's true i have separetad js file for ajax.

– Patrik
Mar 7 at 9:49













Thats why it is not working. for csrf_token use meta tag. and for url pass url as parameter to javascript onclick, or Onchange function. can i see your .js fiile when the ajax will call..

– ThataL
Mar 7 at 9:52





Thats why it is not working. for csrf_token use meta tag. and for url pass url as parameter to javascript onclick, or Onchange function. can i see your .js fiile when the ajax will call..

– ThataL
Mar 7 at 9:52













try my answer as below. I have changed the code by comparing previous and current question of you.

– ThataL
Mar 7 at 10:05





try my answer as below. I have changed the code by comparing previous and current question of you.

– ThataL
Mar 7 at 10:05












5 Answers
5






active

oldest

votes


















0














Since you are working in a JavaScript file and not in a Blade file, the route() helper method is not working, and the route 'race.post' isn't parsed to an url.



Try to change the url to this:



url: '/updateC'


When you want to use the route() helper in your JavaScript, you have to add the script to a Blade file, and json_encode the value, you can read more about this in this answer.






share|improve this answer























  • When i used this way url: '/updateC' it just say method 405(Method not allowed).

    – Patrik
    Mar 7 at 9:39











  • Try to run php artisan route:list and compare the route with the one in your console / network tab. Adapt the route in your ajax call to the one that is shown in your route list.

    – piscator
    Mar 7 at 9:40











  • It say to use createPoints but when i used it the error is 419(Unknown status).

    – Patrik
    Mar 7 at 9:45











  • @Patrik check my answer (comment) from your previous question.

    – ThataL
    Mar 7 at 9:45











  • Nice, that means this issue is resolved. A 419 means the csrf_token is wrong. Does this meta tag exist in your blade file: <meta name="csrf-token" content=" csrf_token() ">? Try to log if jQuery finds the value of the csrf token.

    – piscator
    Mar 7 at 9:49


















0














I have different way to use it:
AJAX



data = 
selectmanufacturer: selectmanufacturer,
categories: selectCategory,
_token: "csrf_token()",
productName: productName
;
$.ajax(
url: 'URL::to('/all-products-data')',
type: 'POST',
dataType: 'json',
data: data,
success: function (response)
,
error: function (response)
alert(response);

);



Controller:



public function Points(Request $request)
$test = $request->all();
return "$test";



I hope It will be helpful to you






share|improve this answer























  • I tried it and it said that the url wasn found 404(Not found).

    – Patrik
    Mar 7 at 9:41











  • have you change url from ajax code because I have given mine url!!!

    – Kinjal Vithalani
    Mar 7 at 10:09


















0














The URL you’re posting to doesn’t look right in the console output you posted. In your AJAX code, you have this:



url:"route('race.post')"


But that’s just getting interpreted as is, it’s not getting interpreted as the value of that route in Laravel.



You’ll need to make sure that your JavaScript code is in a Blade template if you want Blade tags parsed.






share|improve this answer























  • I think he have separte js file thats why csrf_token and url is not working.

    – ThataL
    Mar 7 at 9:49











  • Yes, that’s why I said @Patrik will need to make sure the JavaScript code is in a Blade template.

    – Martin Bean
    Mar 7 at 13:27


















0














not type: "POST", method :'POST" try the below code i have modified. ref: Reference Link
HTML code



<button onClick="onBtnClick()" data-url="route('race.post')"></button>


Updated Code



function onBtnClick()
var token = $('meta[name="csrf-token"]').attr('content');
var url = $(this).attr("data-url");
$.ajax(
method:'POST',
header:
'X-CSRF-TOKEN': token
,
url: url,
data:
_token: token,
dataType: 'json',
contentType:'application/json',

)
.done(function()
alert('success');
)
.fail(function()
alert("error");
);






share|improve this answer
































    0














    add this one in your layout.blade file



    <meta name="csrf-token" content=" csrf_token() ">


    then use this one in your js code



    $.ajaxSetup(
    headers:
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

    );


    i hope this will help!!






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039998%2flaravel-error-405method-not-allowed-ajax-posting%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Since you are working in a JavaScript file and not in a Blade file, the route() helper method is not working, and the route 'race.post' isn't parsed to an url.



      Try to change the url to this:



      url: '/updateC'


      When you want to use the route() helper in your JavaScript, you have to add the script to a Blade file, and json_encode the value, you can read more about this in this answer.






      share|improve this answer























      • When i used this way url: '/updateC' it just say method 405(Method not allowed).

        – Patrik
        Mar 7 at 9:39











      • Try to run php artisan route:list and compare the route with the one in your console / network tab. Adapt the route in your ajax call to the one that is shown in your route list.

        – piscator
        Mar 7 at 9:40











      • It say to use createPoints but when i used it the error is 419(Unknown status).

        – Patrik
        Mar 7 at 9:45











      • @Patrik check my answer (comment) from your previous question.

        – ThataL
        Mar 7 at 9:45











      • Nice, that means this issue is resolved. A 419 means the csrf_token is wrong. Does this meta tag exist in your blade file: <meta name="csrf-token" content=" csrf_token() ">? Try to log if jQuery finds the value of the csrf token.

        – piscator
        Mar 7 at 9:49















      0














      Since you are working in a JavaScript file and not in a Blade file, the route() helper method is not working, and the route 'race.post' isn't parsed to an url.



      Try to change the url to this:



      url: '/updateC'


      When you want to use the route() helper in your JavaScript, you have to add the script to a Blade file, and json_encode the value, you can read more about this in this answer.






      share|improve this answer























      • When i used this way url: '/updateC' it just say method 405(Method not allowed).

        – Patrik
        Mar 7 at 9:39











      • Try to run php artisan route:list and compare the route with the one in your console / network tab. Adapt the route in your ajax call to the one that is shown in your route list.

        – piscator
        Mar 7 at 9:40











      • It say to use createPoints but when i used it the error is 419(Unknown status).

        – Patrik
        Mar 7 at 9:45











      • @Patrik check my answer (comment) from your previous question.

        – ThataL
        Mar 7 at 9:45











      • Nice, that means this issue is resolved. A 419 means the csrf_token is wrong. Does this meta tag exist in your blade file: <meta name="csrf-token" content=" csrf_token() ">? Try to log if jQuery finds the value of the csrf token.

        – piscator
        Mar 7 at 9:49













      0












      0








      0







      Since you are working in a JavaScript file and not in a Blade file, the route() helper method is not working, and the route 'race.post' isn't parsed to an url.



      Try to change the url to this:



      url: '/updateC'


      When you want to use the route() helper in your JavaScript, you have to add the script to a Blade file, and json_encode the value, you can read more about this in this answer.






      share|improve this answer













      Since you are working in a JavaScript file and not in a Blade file, the route() helper method is not working, and the route 'race.post' isn't parsed to an url.



      Try to change the url to this:



      url: '/updateC'


      When you want to use the route() helper in your JavaScript, you have to add the script to a Blade file, and json_encode the value, you can read more about this in this answer.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 7 at 9:24









      piscatorpiscator

      2,96421023




      2,96421023












      • When i used this way url: '/updateC' it just say method 405(Method not allowed).

        – Patrik
        Mar 7 at 9:39











      • Try to run php artisan route:list and compare the route with the one in your console / network tab. Adapt the route in your ajax call to the one that is shown in your route list.

        – piscator
        Mar 7 at 9:40











      • It say to use createPoints but when i used it the error is 419(Unknown status).

        – Patrik
        Mar 7 at 9:45











      • @Patrik check my answer (comment) from your previous question.

        – ThataL
        Mar 7 at 9:45











      • Nice, that means this issue is resolved. A 419 means the csrf_token is wrong. Does this meta tag exist in your blade file: <meta name="csrf-token" content=" csrf_token() ">? Try to log if jQuery finds the value of the csrf token.

        – piscator
        Mar 7 at 9:49

















      • When i used this way url: '/updateC' it just say method 405(Method not allowed).

        – Patrik
        Mar 7 at 9:39











      • Try to run php artisan route:list and compare the route with the one in your console / network tab. Adapt the route in your ajax call to the one that is shown in your route list.

        – piscator
        Mar 7 at 9:40











      • It say to use createPoints but when i used it the error is 419(Unknown status).

        – Patrik
        Mar 7 at 9:45











      • @Patrik check my answer (comment) from your previous question.

        – ThataL
        Mar 7 at 9:45











      • Nice, that means this issue is resolved. A 419 means the csrf_token is wrong. Does this meta tag exist in your blade file: <meta name="csrf-token" content=" csrf_token() ">? Try to log if jQuery finds the value of the csrf token.

        – piscator
        Mar 7 at 9:49
















      When i used this way url: '/updateC' it just say method 405(Method not allowed).

      – Patrik
      Mar 7 at 9:39





      When i used this way url: '/updateC' it just say method 405(Method not allowed).

      – Patrik
      Mar 7 at 9:39













      Try to run php artisan route:list and compare the route with the one in your console / network tab. Adapt the route in your ajax call to the one that is shown in your route list.

      – piscator
      Mar 7 at 9:40





      Try to run php artisan route:list and compare the route with the one in your console / network tab. Adapt the route in your ajax call to the one that is shown in your route list.

      – piscator
      Mar 7 at 9:40













      It say to use createPoints but when i used it the error is 419(Unknown status).

      – Patrik
      Mar 7 at 9:45





      It say to use createPoints but when i used it the error is 419(Unknown status).

      – Patrik
      Mar 7 at 9:45













      @Patrik check my answer (comment) from your previous question.

      – ThataL
      Mar 7 at 9:45





      @Patrik check my answer (comment) from your previous question.

      – ThataL
      Mar 7 at 9:45













      Nice, that means this issue is resolved. A 419 means the csrf_token is wrong. Does this meta tag exist in your blade file: <meta name="csrf-token" content=" csrf_token() ">? Try to log if jQuery finds the value of the csrf token.

      – piscator
      Mar 7 at 9:49





      Nice, that means this issue is resolved. A 419 means the csrf_token is wrong. Does this meta tag exist in your blade file: <meta name="csrf-token" content=" csrf_token() ">? Try to log if jQuery finds the value of the csrf token.

      – piscator
      Mar 7 at 9:49













      0














      I have different way to use it:
      AJAX



      data = 
      selectmanufacturer: selectmanufacturer,
      categories: selectCategory,
      _token: "csrf_token()",
      productName: productName
      ;
      $.ajax(
      url: 'URL::to('/all-products-data')',
      type: 'POST',
      dataType: 'json',
      data: data,
      success: function (response)
      ,
      error: function (response)
      alert(response);

      );



      Controller:



      public function Points(Request $request)
      $test = $request->all();
      return "$test";



      I hope It will be helpful to you






      share|improve this answer























      • I tried it and it said that the url wasn found 404(Not found).

        – Patrik
        Mar 7 at 9:41











      • have you change url from ajax code because I have given mine url!!!

        – Kinjal Vithalani
        Mar 7 at 10:09















      0














      I have different way to use it:
      AJAX



      data = 
      selectmanufacturer: selectmanufacturer,
      categories: selectCategory,
      _token: "csrf_token()",
      productName: productName
      ;
      $.ajax(
      url: 'URL::to('/all-products-data')',
      type: 'POST',
      dataType: 'json',
      data: data,
      success: function (response)
      ,
      error: function (response)
      alert(response);

      );



      Controller:



      public function Points(Request $request)
      $test = $request->all();
      return "$test";



      I hope It will be helpful to you






      share|improve this answer























      • I tried it and it said that the url wasn found 404(Not found).

        – Patrik
        Mar 7 at 9:41











      • have you change url from ajax code because I have given mine url!!!

        – Kinjal Vithalani
        Mar 7 at 10:09













      0












      0








      0







      I have different way to use it:
      AJAX



      data = 
      selectmanufacturer: selectmanufacturer,
      categories: selectCategory,
      _token: "csrf_token()",
      productName: productName
      ;
      $.ajax(
      url: 'URL::to('/all-products-data')',
      type: 'POST',
      dataType: 'json',
      data: data,
      success: function (response)
      ,
      error: function (response)
      alert(response);

      );



      Controller:



      public function Points(Request $request)
      $test = $request->all();
      return "$test";



      I hope It will be helpful to you






      share|improve this answer













      I have different way to use it:
      AJAX



      data = 
      selectmanufacturer: selectmanufacturer,
      categories: selectCategory,
      _token: "csrf_token()",
      productName: productName
      ;
      $.ajax(
      url: 'URL::to('/all-products-data')',
      type: 'POST',
      dataType: 'json',
      data: data,
      success: function (response)
      ,
      error: function (response)
      alert(response);

      );



      Controller:



      public function Points(Request $request)
      $test = $request->all();
      return "$test";



      I hope It will be helpful to you







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 7 at 9:27









      Kinjal VithalaniKinjal Vithalani

      2816




      2816












      • I tried it and it said that the url wasn found 404(Not found).

        – Patrik
        Mar 7 at 9:41











      • have you change url from ajax code because I have given mine url!!!

        – Kinjal Vithalani
        Mar 7 at 10:09

















      • I tried it and it said that the url wasn found 404(Not found).

        – Patrik
        Mar 7 at 9:41











      • have you change url from ajax code because I have given mine url!!!

        – Kinjal Vithalani
        Mar 7 at 10:09
















      I tried it and it said that the url wasn found 404(Not found).

      – Patrik
      Mar 7 at 9:41





      I tried it and it said that the url wasn found 404(Not found).

      – Patrik
      Mar 7 at 9:41













      have you change url from ajax code because I have given mine url!!!

      – Kinjal Vithalani
      Mar 7 at 10:09





      have you change url from ajax code because I have given mine url!!!

      – Kinjal Vithalani
      Mar 7 at 10:09











      0














      The URL you’re posting to doesn’t look right in the console output you posted. In your AJAX code, you have this:



      url:"route('race.post')"


      But that’s just getting interpreted as is, it’s not getting interpreted as the value of that route in Laravel.



      You’ll need to make sure that your JavaScript code is in a Blade template if you want Blade tags parsed.






      share|improve this answer























      • I think he have separte js file thats why csrf_token and url is not working.

        – ThataL
        Mar 7 at 9:49











      • Yes, that’s why I said @Patrik will need to make sure the JavaScript code is in a Blade template.

        – Martin Bean
        Mar 7 at 13:27















      0














      The URL you’re posting to doesn’t look right in the console output you posted. In your AJAX code, you have this:



      url:"route('race.post')"


      But that’s just getting interpreted as is, it’s not getting interpreted as the value of that route in Laravel.



      You’ll need to make sure that your JavaScript code is in a Blade template if you want Blade tags parsed.






      share|improve this answer























      • I think he have separte js file thats why csrf_token and url is not working.

        – ThataL
        Mar 7 at 9:49











      • Yes, that’s why I said @Patrik will need to make sure the JavaScript code is in a Blade template.

        – Martin Bean
        Mar 7 at 13:27













      0












      0








      0







      The URL you’re posting to doesn’t look right in the console output you posted. In your AJAX code, you have this:



      url:"route('race.post')"


      But that’s just getting interpreted as is, it’s not getting interpreted as the value of that route in Laravel.



      You’ll need to make sure that your JavaScript code is in a Blade template if you want Blade tags parsed.






      share|improve this answer













      The URL you’re posting to doesn’t look right in the console output you posted. In your AJAX code, you have this:



      url:"route('race.post')"


      But that’s just getting interpreted as is, it’s not getting interpreted as the value of that route in Laravel.



      You’ll need to make sure that your JavaScript code is in a Blade template if you want Blade tags parsed.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 7 at 9:27









      Martin BeanMartin Bean

      24.9k1995165




      24.9k1995165












      • I think he have separte js file thats why csrf_token and url is not working.

        – ThataL
        Mar 7 at 9:49











      • Yes, that’s why I said @Patrik will need to make sure the JavaScript code is in a Blade template.

        – Martin Bean
        Mar 7 at 13:27

















      • I think he have separte js file thats why csrf_token and url is not working.

        – ThataL
        Mar 7 at 9:49











      • Yes, that’s why I said @Patrik will need to make sure the JavaScript code is in a Blade template.

        – Martin Bean
        Mar 7 at 13:27
















      I think he have separte js file thats why csrf_token and url is not working.

      – ThataL
      Mar 7 at 9:49





      I think he have separte js file thats why csrf_token and url is not working.

      – ThataL
      Mar 7 at 9:49













      Yes, that’s why I said @Patrik will need to make sure the JavaScript code is in a Blade template.

      – Martin Bean
      Mar 7 at 13:27





      Yes, that’s why I said @Patrik will need to make sure the JavaScript code is in a Blade template.

      – Martin Bean
      Mar 7 at 13:27











      0














      not type: "POST", method :'POST" try the below code i have modified. ref: Reference Link
      HTML code



      <button onClick="onBtnClick()" data-url="route('race.post')"></button>


      Updated Code



      function onBtnClick()
      var token = $('meta[name="csrf-token"]').attr('content');
      var url = $(this).attr("data-url");
      $.ajax(
      method:'POST',
      header:
      'X-CSRF-TOKEN': token
      ,
      url: url,
      data:
      _token: token,
      dataType: 'json',
      contentType:'application/json',

      )
      .done(function()
      alert('success');
      )
      .fail(function()
      alert("error");
      );






      share|improve this answer





























        0














        not type: "POST", method :'POST" try the below code i have modified. ref: Reference Link
        HTML code



        <button onClick="onBtnClick()" data-url="route('race.post')"></button>


        Updated Code



        function onBtnClick()
        var token = $('meta[name="csrf-token"]').attr('content');
        var url = $(this).attr("data-url");
        $.ajax(
        method:'POST',
        header:
        'X-CSRF-TOKEN': token
        ,
        url: url,
        data:
        _token: token,
        dataType: 'json',
        contentType:'application/json',

        )
        .done(function()
        alert('success');
        )
        .fail(function()
        alert("error");
        );






        share|improve this answer



























          0












          0








          0







          not type: "POST", method :'POST" try the below code i have modified. ref: Reference Link
          HTML code



          <button onClick="onBtnClick()" data-url="route('race.post')"></button>


          Updated Code



          function onBtnClick()
          var token = $('meta[name="csrf-token"]').attr('content');
          var url = $(this).attr("data-url");
          $.ajax(
          method:'POST',
          header:
          'X-CSRF-TOKEN': token
          ,
          url: url,
          data:
          _token: token,
          dataType: 'json',
          contentType:'application/json',

          )
          .done(function()
          alert('success');
          )
          .fail(function()
          alert("error");
          );






          share|improve this answer















          not type: "POST", method :'POST" try the below code i have modified. ref: Reference Link
          HTML code



          <button onClick="onBtnClick()" data-url="route('race.post')"></button>


          Updated Code



          function onBtnClick()
          var token = $('meta[name="csrf-token"]').attr('content');
          var url = $(this).attr("data-url");
          $.ajax(
          method:'POST',
          header:
          'X-CSRF-TOKEN': token
          ,
          url: url,
          data:
          _token: token,
          dataType: 'json',
          contentType:'application/json',

          )
          .done(function()
          alert('success');
          )
          .fail(function()
          alert("error");
          );







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 7 at 10:02

























          answered Mar 7 at 9:34









          ThataLThataL

          12719




          12719





















              0














              add this one in your layout.blade file



              <meta name="csrf-token" content=" csrf_token() ">


              then use this one in your js code



              $.ajaxSetup(
              headers:
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

              );


              i hope this will help!!






              share|improve this answer



























                0














                add this one in your layout.blade file



                <meta name="csrf-token" content=" csrf_token() ">


                then use this one in your js code



                $.ajaxSetup(
                headers:
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

                );


                i hope this will help!!






                share|improve this answer

























                  0












                  0








                  0







                  add this one in your layout.blade file



                  <meta name="csrf-token" content=" csrf_token() ">


                  then use this one in your js code



                  $.ajaxSetup(
                  headers:
                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

                  );


                  i hope this will help!!






                  share|improve this answer













                  add this one in your layout.blade file



                  <meta name="csrf-token" content=" csrf_token() ">


                  then use this one in your js code



                  $.ajaxSetup(
                  headers:
                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')

                  );


                  i hope this will help!!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 12:30









                  sandysandy

                  283112




                  283112



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55039998%2flaravel-error-405method-not-allowed-ajax-posting%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived