laravel ajax is not working , it seen fail
i want to insert data from register form by ajax.
but I see ajax failed
in my console log.
I can't understand what is problem ?
here is my js :
$('#Personal_Information').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax
({
type: "POST",
dataType : 'json',
url: "{{url('all/update-profile')}}",
data: {csrf_token:"{{csrf_token()}}", data: form_data}
}).done( function(data){
console.log('Ajax was Successful!')
console.log(data)
}).fail(function(){
console.log('Ajax Failed')
});
here is my route :
Route::get('/update-profile', 'personalinformation@redirectupdatepage')->name('/all.update-profile');
Route::post('/all/update-profile', 'personalinformation@store');
my controller's code :
public function store(Request $request)
{
$modal = User::create($request->all());
return $modal;
}
Thanks.
laravel laravel-5
add a comment |
i want to insert data from register form by ajax.
but I see ajax failed
in my console log.
I can't understand what is problem ?
here is my js :
$('#Personal_Information').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax
({
type: "POST",
dataType : 'json',
url: "{{url('all/update-profile')}}",
data: {csrf_token:"{{csrf_token()}}", data: form_data}
}).done( function(data){
console.log('Ajax was Successful!')
console.log(data)
}).fail(function(){
console.log('Ajax Failed')
});
here is my route :
Route::get('/update-profile', 'personalinformation@redirectupdatepage')->name('/all.update-profile');
Route::post('/all/update-profile', 'personalinformation@store');
my controller's code :
public function store(Request $request)
{
$modal = User::create($request->all());
return $modal;
}
Thanks.
laravel laravel-5
Could you change your.fail(function())
callback to.fail(function(xhr, textStatus, error))
? Then console.logxhr.responseText
so we can know the actual error :)
– Mozammil
Jan 2 at 7:42
"Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
add a comment |
i want to insert data from register form by ajax.
but I see ajax failed
in my console log.
I can't understand what is problem ?
here is my js :
$('#Personal_Information').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax
({
type: "POST",
dataType : 'json',
url: "{{url('all/update-profile')}}",
data: {csrf_token:"{{csrf_token()}}", data: form_data}
}).done( function(data){
console.log('Ajax was Successful!')
console.log(data)
}).fail(function(){
console.log('Ajax Failed')
});
here is my route :
Route::get('/update-profile', 'personalinformation@redirectupdatepage')->name('/all.update-profile');
Route::post('/all/update-profile', 'personalinformation@store');
my controller's code :
public function store(Request $request)
{
$modal = User::create($request->all());
return $modal;
}
Thanks.
laravel laravel-5
i want to insert data from register form by ajax.
but I see ajax failed
in my console log.
I can't understand what is problem ?
here is my js :
$('#Personal_Information').on('submit', function(event){
event.preventDefault();
var form_data = $(this).serialize();
$.ajax
({
type: "POST",
dataType : 'json',
url: "{{url('all/update-profile')}}",
data: {csrf_token:"{{csrf_token()}}", data: form_data}
}).done( function(data){
console.log('Ajax was Successful!')
console.log(data)
}).fail(function(){
console.log('Ajax Failed')
});
here is my route :
Route::get('/update-profile', 'personalinformation@redirectupdatepage')->name('/all.update-profile');
Route::post('/all/update-profile', 'personalinformation@store');
my controller's code :
public function store(Request $request)
{
$modal = User::create($request->all());
return $modal;
}
Thanks.
laravel laravel-5
laravel laravel-5
asked Jan 2 at 7:37
NirabNirab
3618
3618
Could you change your.fail(function())
callback to.fail(function(xhr, textStatus, error))
? Then console.logxhr.responseText
so we can know the actual error :)
– Mozammil
Jan 2 at 7:42
"Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
add a comment |
Could you change your.fail(function())
callback to.fail(function(xhr, textStatus, error))
? Then console.logxhr.responseText
so we can know the actual error :)
– Mozammil
Jan 2 at 7:42
"Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
Could you change your
.fail(function())
callback to .fail(function(xhr, textStatus, error))
? Then console.log xhr.responseText
so we can know the actual error :)– Mozammil
Jan 2 at 7:42
Could you change your
.fail(function())
callback to .fail(function(xhr, textStatus, error))
? Then console.log xhr.responseText
so we can know the actual error :)– Mozammil
Jan 2 at 7:42
"Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
"Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
add a comment |
1 Answer
1
active
oldest
votes
Your token field name must be _token,
Update your code, this line.
data: { _token:"{{csrf_token()}}", data: form_data},
Best solution is add meta tag and header.
<meta name="csrf-token" content="{{ csrf_token() }}" />
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
Update Your Controller.
public function store(Request $request)
{
$modal = User::create($request->get('data'));
return $modal;
}
thanks ... its improvement answer ..... i see now "Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
sorry to say ...its not solved
– Nirab
Jan 2 at 7:58
You have to update your controller store method like above
– Md.Sukel Ali
Jan 2 at 8:01
thanks , i hope its my controller's problem
– Nirab
Jan 2 at 8:05
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%2f54002782%2flaravel-ajax-is-not-working-it-seen-fail%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your token field name must be _token,
Update your code, this line.
data: { _token:"{{csrf_token()}}", data: form_data},
Best solution is add meta tag and header.
<meta name="csrf-token" content="{{ csrf_token() }}" />
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
Update Your Controller.
public function store(Request $request)
{
$modal = User::create($request->get('data'));
return $modal;
}
thanks ... its improvement answer ..... i see now "Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
sorry to say ...its not solved
– Nirab
Jan 2 at 7:58
You have to update your controller store method like above
– Md.Sukel Ali
Jan 2 at 8:01
thanks , i hope its my controller's problem
– Nirab
Jan 2 at 8:05
add a comment |
Your token field name must be _token,
Update your code, this line.
data: { _token:"{{csrf_token()}}", data: form_data},
Best solution is add meta tag and header.
<meta name="csrf-token" content="{{ csrf_token() }}" />
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
Update Your Controller.
public function store(Request $request)
{
$modal = User::create($request->get('data'));
return $modal;
}
thanks ... its improvement answer ..... i see now "Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
sorry to say ...its not solved
– Nirab
Jan 2 at 7:58
You have to update your controller store method like above
– Md.Sukel Ali
Jan 2 at 8:01
thanks , i hope its my controller's problem
– Nirab
Jan 2 at 8:05
add a comment |
Your token field name must be _token,
Update your code, this line.
data: { _token:"{{csrf_token()}}", data: form_data},
Best solution is add meta tag and header.
<meta name="csrf-token" content="{{ csrf_token() }}" />
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
Update Your Controller.
public function store(Request $request)
{
$modal = User::create($request->get('data'));
return $modal;
}
Your token field name must be _token,
Update your code, this line.
data: { _token:"{{csrf_token()}}", data: form_data},
Best solution is add meta tag and header.
<meta name="csrf-token" content="{{ csrf_token() }}" />
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
Update Your Controller.
public function store(Request $request)
{
$modal = User::create($request->get('data'));
return $modal;
}
edited Jan 2 at 8:00
answered Jan 2 at 7:45


Md.Sukel AliMd.Sukel Ali
1,2351818
1,2351818
thanks ... its improvement answer ..... i see now "Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
sorry to say ...its not solved
– Nirab
Jan 2 at 7:58
You have to update your controller store method like above
– Md.Sukel Ali
Jan 2 at 8:01
thanks , i hope its my controller's problem
– Nirab
Jan 2 at 8:05
add a comment |
thanks ... its improvement answer ..... i see now "Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
sorry to say ...its not solved
– Nirab
Jan 2 at 7:58
You have to update your controller store method like above
– Md.Sukel Ali
Jan 2 at 8:01
thanks , i hope its my controller's problem
– Nirab
Jan 2 at 8:05
thanks ... its improvement answer ..... i see now "Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
thanks ... its improvement answer ..... i see now "Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50
sorry to say ...its not solved
– Nirab
Jan 2 at 7:58
sorry to say ...its not solved
– Nirab
Jan 2 at 7:58
You have to update your controller store method like above
– Md.Sukel Ali
Jan 2 at 8:01
You have to update your controller store method like above
– Md.Sukel Ali
Jan 2 at 8:01
thanks , i hope its my controller's problem
– Nirab
Jan 2 at 8:05
thanks , i hope its my controller's problem
– Nirab
Jan 2 at 8:05
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%2f54002782%2flaravel-ajax-is-not-working-it-seen-fail%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
Could you change your
.fail(function())
callback to.fail(function(xhr, textStatus, error))
? Then console.logxhr.responseText
so we can know the actual error :)– Mozammil
Jan 2 at 7:42
"Internal Server Error" in my console.log
– Nirab
Jan 2 at 7:50