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
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
add a comment |
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
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
add a comment |
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
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
javascript ajax laravel
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
add a comment |
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
add a comment |
5 Answers
5
active
oldest
votes
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.
When i used this wayurl: '/updateC'
it just say method 405(Method not allowed).
– Patrik
Mar 7 at 9:39
Try to runphp 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 usecreatePoints
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 thecsrf_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
add a comment |
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
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
add a comment |
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.
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
add a comment |
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");
);
add a comment |
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!!
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
When i used this wayurl: '/updateC'
it just say method 405(Method not allowed).
– Patrik
Mar 7 at 9:39
Try to runphp 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 usecreatePoints
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 thecsrf_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
add a comment |
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.
When i used this wayurl: '/updateC'
it just say method 405(Method not allowed).
– Patrik
Mar 7 at 9:39
Try to runphp 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 usecreatePoints
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 thecsrf_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
add a comment |
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.
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.
answered Mar 7 at 9:24
piscatorpiscator
2,96421023
2,96421023
When i used this wayurl: '/updateC'
it just say method 405(Method not allowed).
– Patrik
Mar 7 at 9:39
Try to runphp 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 usecreatePoints
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 thecsrf_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
add a comment |
When i used this wayurl: '/updateC'
it just say method 405(Method not allowed).
– Patrik
Mar 7 at 9:39
Try to runphp 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 usecreatePoints
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 thecsrf_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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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");
);
add a comment |
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");
);
add a comment |
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");
);
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");
);
edited Mar 7 at 10:02
answered Mar 7 at 9:34
ThataLThataL
12719
12719
add a comment |
add a comment |
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!!
add a comment |
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!!
add a comment |
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!!
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!!
answered Mar 7 at 12:30
sandysandy
283112
283112
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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