Action not found after AJAX request











up vote
2
down vote

favorite












Before for submitting I want to send the request to an action. But in return I get 404 not found. The action is obviously there. Also got it in the filters of the controller.
JS:



$('#home-contact').on('beforeSubmit', function(){
$.ajax({
method: 'post',
url: '/site/send-contact',
data: new FormData($(this))[0],
success: function(data){
console.log(data)
}
})
return false
})


Controller filters:



'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'send-contact'],
'rules' => [
[
'actions' => ['signup', 'send-contact'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],


And the action also :



public function actionSendContact()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$model = new Contact();
if($model->load(Yii::$app->request->post()) && $model->save()){
return $data['success'] = Yii::t('app', 'Successfully sent message.');
}
return $data['error'] = Yii::t('app', 'Something went wrong. Please try again.');
}


The scenario happens in the frontend if that matters somehow. Thank you!










share|improve this question
























  • what url does the request in console shows up is that correct can you add the image of that request? if you write that same url in the browser what do you see?
    – Muhammad Omer Aslam
    Nov 18 at 12:46












  • and what is the reason behind not using $.serialize() and using new FormData() instead ?
    – Muhammad Omer Aslam
    Nov 18 at 13:23















up vote
2
down vote

favorite












Before for submitting I want to send the request to an action. But in return I get 404 not found. The action is obviously there. Also got it in the filters of the controller.
JS:



$('#home-contact').on('beforeSubmit', function(){
$.ajax({
method: 'post',
url: '/site/send-contact',
data: new FormData($(this))[0],
success: function(data){
console.log(data)
}
})
return false
})


Controller filters:



'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'send-contact'],
'rules' => [
[
'actions' => ['signup', 'send-contact'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],


And the action also :



public function actionSendContact()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$model = new Contact();
if($model->load(Yii::$app->request->post()) && $model->save()){
return $data['success'] = Yii::t('app', 'Successfully sent message.');
}
return $data['error'] = Yii::t('app', 'Something went wrong. Please try again.');
}


The scenario happens in the frontend if that matters somehow. Thank you!










share|improve this question
























  • what url does the request in console shows up is that correct can you add the image of that request? if you write that same url in the browser what do you see?
    – Muhammad Omer Aslam
    Nov 18 at 12:46












  • and what is the reason behind not using $.serialize() and using new FormData() instead ?
    – Muhammad Omer Aslam
    Nov 18 at 13:23













up vote
2
down vote

favorite









up vote
2
down vote

favorite











Before for submitting I want to send the request to an action. But in return I get 404 not found. The action is obviously there. Also got it in the filters of the controller.
JS:



$('#home-contact').on('beforeSubmit', function(){
$.ajax({
method: 'post',
url: '/site/send-contact',
data: new FormData($(this))[0],
success: function(data){
console.log(data)
}
})
return false
})


Controller filters:



'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'send-contact'],
'rules' => [
[
'actions' => ['signup', 'send-contact'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],


And the action also :



public function actionSendContact()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$model = new Contact();
if($model->load(Yii::$app->request->post()) && $model->save()){
return $data['success'] = Yii::t('app', 'Successfully sent message.');
}
return $data['error'] = Yii::t('app', 'Something went wrong. Please try again.');
}


The scenario happens in the frontend if that matters somehow. Thank you!










share|improve this question















Before for submitting I want to send the request to an action. But in return I get 404 not found. The action is obviously there. Also got it in the filters of the controller.
JS:



$('#home-contact').on('beforeSubmit', function(){
$.ajax({
method: 'post',
url: '/site/send-contact',
data: new FormData($(this))[0],
success: function(data){
console.log(data)
}
})
return false
})


Controller filters:



'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup', 'send-contact'],
'rules' => [
[
'actions' => ['signup', 'send-contact'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],


And the action also :



public function actionSendContact()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$model = new Contact();
if($model->load(Yii::$app->request->post()) && $model->save()){
return $data['success'] = Yii::t('app', 'Successfully sent message.');
}
return $data['error'] = Yii::t('app', 'Something went wrong. Please try again.');
}


The scenario happens in the frontend if that matters somehow. Thank you!







yii2 yii2-advanced-app






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 1:47









Muhammad Omer Aslam

11.6k62344




11.6k62344










asked Nov 17 at 19:56









Toma Tomov

554216




554216












  • what url does the request in console shows up is that correct can you add the image of that request? if you write that same url in the browser what do you see?
    – Muhammad Omer Aslam
    Nov 18 at 12:46












  • and what is the reason behind not using $.serialize() and using new FormData() instead ?
    – Muhammad Omer Aslam
    Nov 18 at 13:23


















  • what url does the request in console shows up is that correct can you add the image of that request? if you write that same url in the browser what do you see?
    – Muhammad Omer Aslam
    Nov 18 at 12:46












  • and what is the reason behind not using $.serialize() and using new FormData() instead ?
    – Muhammad Omer Aslam
    Nov 18 at 13:23
















what url does the request in console shows up is that correct can you add the image of that request? if you write that same url in the browser what do you see?
– Muhammad Omer Aslam
Nov 18 at 12:46






what url does the request in console shows up is that correct can you add the image of that request? if you write that same url in the browser what do you see?
– Muhammad Omer Aslam
Nov 18 at 12:46














and what is the reason behind not using $.serialize() and using new FormData() instead ?
– Muhammad Omer Aslam
Nov 18 at 13:23




and what is the reason behind not using $.serialize() and using new FormData() instead ?
– Muhammad Omer Aslam
Nov 18 at 13:23












3 Answers
3






active

oldest

votes

















up vote
2
down vote



accepted










Not sure about the 404 you are having as the url in the request is correct and the url that would be generated for the ajax request will be like http://example.com/site/send-contact but only if you are using the 'enablePrettyUrl' => true, for the urlManager component, otherwise it should be like index.php?r=site/index that could only be the reason behind the 404, a better way is to get the url from the form action attribute.



Apart from above,



You are using the new FormData() to send the data with the request like



data: new FormData($(this))[0] 


which isn't correct and won't send any FormData with the request as it will return undefined, you can check the console or by using the print_r($_POST) inside the action sendContact once you are done with the 404, it should be



data: new FormData($(this)[0]),


you need to get the form via $(this)[0] and pass to the new FormData().



But this is not enough you have to set the contentType and processData to be false to correctly submit the FormData or you will get the exception in console




Uncaught TypeError: Illegal invocation




So your code should be like



$('#contact-form').on('beforeSubmit', function(){
let url=$(this).attr('action');
let form=$(this)[0];
let data=new FormData(form);

$.ajax({
method: 'post',
url: url,
data:data,
contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
processData: false,
success: function(data){
console.log(data)
}
});
return false;
})


EDIT



Note: Above all you should use data:$(form).serialize() simply rather than using new FormData() until unless you are planning to upload files along with the form using ajax.






share|improve this answer























  • I found the problem. It was in my url parsing controller ( I got custom one ). But about the jQuery - I am really thankful! Will read more about the contetnType and processData now. I can mark your answer as correct because it did explain something that can be helpful for someone else. Hope stackoverflow doesn't mind it.
    – Toma Tomov
    Nov 18 at 19:23








  • 1




    you should use data:$(form).serialize() simply rather than using FormData until unless you are planning to upload files along with the form using ajax. @TomaTomov
    – Muhammad Omer Aslam
    Nov 18 at 20:16




















up vote
1
down vote













URL in JavaScript seems to be not fully specified.



The valid way would be:



url: 'index.php?r=site/send-contact',


But this works only if your index.php is in root folder.



To make it work with any situation (e.g., index.php is not in root), then you have different solutions. I personally like to use this:




  • Declare action and id in your form:


Example:



$form = ActiveForm::begin([
'action' => ['site/send-contact'],
'id' => 'my-form',
]);



  • Use a link (that is generated by Yii2 itself) in your JS code:


Example:



$('#home-contact').on('beforeSubmit', function() {
$.ajax({
method: 'post',
url: $('#my-form').attr('action'),
data: new FormData($(this))[0],
success: function(data) {
console.log(data)
}
});

return false;
});


This should work in all cases, whenever your files are.



Hope that helps!






share|improve this answer





















  • whats with new FormData($(this))[0] ? this will give undefined
    – Muhammad Omer Aslam
    Nov 20 at 1:31












  • I used what OP gave in a question. I was looking only at url: part here.
    – Gytis Tenovimas
    Nov 20 at 12:09


















up vote
-1
down vote













did you add 'enableAjaxValidation' => true or add action name in active form?



$form = ActiveForm::begin([
'action' => ['controller/action'],
'enableAjaxValidation' => true
]);





share|improve this answer

















  • 2




    Why do I need to enable it when I am sending the AJAX request by myself ?
    – Toma Tomov
    Nov 17 at 21:06










  • yeah sorry, add a complete route in your URL in JS file @TomaTomov
    – Mehran
    Nov 18 at 5:34












  • ajax validation has nothing to do with it
    – Muhammad Omer Aslam
    Nov 18 at 12:47











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',
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%2f53355009%2faction-not-found-after-ajax-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










Not sure about the 404 you are having as the url in the request is correct and the url that would be generated for the ajax request will be like http://example.com/site/send-contact but only if you are using the 'enablePrettyUrl' => true, for the urlManager component, otherwise it should be like index.php?r=site/index that could only be the reason behind the 404, a better way is to get the url from the form action attribute.



Apart from above,



You are using the new FormData() to send the data with the request like



data: new FormData($(this))[0] 


which isn't correct and won't send any FormData with the request as it will return undefined, you can check the console or by using the print_r($_POST) inside the action sendContact once you are done with the 404, it should be



data: new FormData($(this)[0]),


you need to get the form via $(this)[0] and pass to the new FormData().



But this is not enough you have to set the contentType and processData to be false to correctly submit the FormData or you will get the exception in console




Uncaught TypeError: Illegal invocation




So your code should be like



$('#contact-form').on('beforeSubmit', function(){
let url=$(this).attr('action');
let form=$(this)[0];
let data=new FormData(form);

$.ajax({
method: 'post',
url: url,
data:data,
contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
processData: false,
success: function(data){
console.log(data)
}
});
return false;
})


EDIT



Note: Above all you should use data:$(form).serialize() simply rather than using new FormData() until unless you are planning to upload files along with the form using ajax.






share|improve this answer























  • I found the problem. It was in my url parsing controller ( I got custom one ). But about the jQuery - I am really thankful! Will read more about the contetnType and processData now. I can mark your answer as correct because it did explain something that can be helpful for someone else. Hope stackoverflow doesn't mind it.
    – Toma Tomov
    Nov 18 at 19:23








  • 1




    you should use data:$(form).serialize() simply rather than using FormData until unless you are planning to upload files along with the form using ajax. @TomaTomov
    – Muhammad Omer Aslam
    Nov 18 at 20:16

















up vote
2
down vote



accepted










Not sure about the 404 you are having as the url in the request is correct and the url that would be generated for the ajax request will be like http://example.com/site/send-contact but only if you are using the 'enablePrettyUrl' => true, for the urlManager component, otherwise it should be like index.php?r=site/index that could only be the reason behind the 404, a better way is to get the url from the form action attribute.



Apart from above,



You are using the new FormData() to send the data with the request like



data: new FormData($(this))[0] 


which isn't correct and won't send any FormData with the request as it will return undefined, you can check the console or by using the print_r($_POST) inside the action sendContact once you are done with the 404, it should be



data: new FormData($(this)[0]),


you need to get the form via $(this)[0] and pass to the new FormData().



But this is not enough you have to set the contentType and processData to be false to correctly submit the FormData or you will get the exception in console




Uncaught TypeError: Illegal invocation




So your code should be like



$('#contact-form').on('beforeSubmit', function(){
let url=$(this).attr('action');
let form=$(this)[0];
let data=new FormData(form);

$.ajax({
method: 'post',
url: url,
data:data,
contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
processData: false,
success: function(data){
console.log(data)
}
});
return false;
})


EDIT



Note: Above all you should use data:$(form).serialize() simply rather than using new FormData() until unless you are planning to upload files along with the form using ajax.






share|improve this answer























  • I found the problem. It was in my url parsing controller ( I got custom one ). But about the jQuery - I am really thankful! Will read more about the contetnType and processData now. I can mark your answer as correct because it did explain something that can be helpful for someone else. Hope stackoverflow doesn't mind it.
    – Toma Tomov
    Nov 18 at 19:23








  • 1




    you should use data:$(form).serialize() simply rather than using FormData until unless you are planning to upload files along with the form using ajax. @TomaTomov
    – Muhammad Omer Aslam
    Nov 18 at 20:16















up vote
2
down vote



accepted







up vote
2
down vote



accepted






Not sure about the 404 you are having as the url in the request is correct and the url that would be generated for the ajax request will be like http://example.com/site/send-contact but only if you are using the 'enablePrettyUrl' => true, for the urlManager component, otherwise it should be like index.php?r=site/index that could only be the reason behind the 404, a better way is to get the url from the form action attribute.



Apart from above,



You are using the new FormData() to send the data with the request like



data: new FormData($(this))[0] 


which isn't correct and won't send any FormData with the request as it will return undefined, you can check the console or by using the print_r($_POST) inside the action sendContact once you are done with the 404, it should be



data: new FormData($(this)[0]),


you need to get the form via $(this)[0] and pass to the new FormData().



But this is not enough you have to set the contentType and processData to be false to correctly submit the FormData or you will get the exception in console




Uncaught TypeError: Illegal invocation




So your code should be like



$('#contact-form').on('beforeSubmit', function(){
let url=$(this).attr('action');
let form=$(this)[0];
let data=new FormData(form);

$.ajax({
method: 'post',
url: url,
data:data,
contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
processData: false,
success: function(data){
console.log(data)
}
});
return false;
})


EDIT



Note: Above all you should use data:$(form).serialize() simply rather than using new FormData() until unless you are planning to upload files along with the form using ajax.






share|improve this answer














Not sure about the 404 you are having as the url in the request is correct and the url that would be generated for the ajax request will be like http://example.com/site/send-contact but only if you are using the 'enablePrettyUrl' => true, for the urlManager component, otherwise it should be like index.php?r=site/index that could only be the reason behind the 404, a better way is to get the url from the form action attribute.



Apart from above,



You are using the new FormData() to send the data with the request like



data: new FormData($(this))[0] 


which isn't correct and won't send any FormData with the request as it will return undefined, you can check the console or by using the print_r($_POST) inside the action sendContact once you are done with the 404, it should be



data: new FormData($(this)[0]),


you need to get the form via $(this)[0] and pass to the new FormData().



But this is not enough you have to set the contentType and processData to be false to correctly submit the FormData or you will get the exception in console




Uncaught TypeError: Illegal invocation




So your code should be like



$('#contact-form').on('beforeSubmit', function(){
let url=$(this).attr('action');
let form=$(this)[0];
let data=new FormData(form);

$.ajax({
method: 'post',
url: url,
data:data,
contentType: false, // NEEDED, DON'T OMIT THIS (requires jQuery 1.6+)
processData: false,
success: function(data){
console.log(data)
}
});
return false;
})


EDIT



Note: Above all you should use data:$(form).serialize() simply rather than using new FormData() until unless you are planning to upload files along with the form using ajax.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 2:09

























answered Nov 18 at 14:51









Muhammad Omer Aslam

11.6k62344




11.6k62344












  • I found the problem. It was in my url parsing controller ( I got custom one ). But about the jQuery - I am really thankful! Will read more about the contetnType and processData now. I can mark your answer as correct because it did explain something that can be helpful for someone else. Hope stackoverflow doesn't mind it.
    – Toma Tomov
    Nov 18 at 19:23








  • 1




    you should use data:$(form).serialize() simply rather than using FormData until unless you are planning to upload files along with the form using ajax. @TomaTomov
    – Muhammad Omer Aslam
    Nov 18 at 20:16




















  • I found the problem. It was in my url parsing controller ( I got custom one ). But about the jQuery - I am really thankful! Will read more about the contetnType and processData now. I can mark your answer as correct because it did explain something that can be helpful for someone else. Hope stackoverflow doesn't mind it.
    – Toma Tomov
    Nov 18 at 19:23








  • 1




    you should use data:$(form).serialize() simply rather than using FormData until unless you are planning to upload files along with the form using ajax. @TomaTomov
    – Muhammad Omer Aslam
    Nov 18 at 20:16


















I found the problem. It was in my url parsing controller ( I got custom one ). But about the jQuery - I am really thankful! Will read more about the contetnType and processData now. I can mark your answer as correct because it did explain something that can be helpful for someone else. Hope stackoverflow doesn't mind it.
– Toma Tomov
Nov 18 at 19:23






I found the problem. It was in my url parsing controller ( I got custom one ). But about the jQuery - I am really thankful! Will read more about the contetnType and processData now. I can mark your answer as correct because it did explain something that can be helpful for someone else. Hope stackoverflow doesn't mind it.
– Toma Tomov
Nov 18 at 19:23






1




1




you should use data:$(form).serialize() simply rather than using FormData until unless you are planning to upload files along with the form using ajax. @TomaTomov
– Muhammad Omer Aslam
Nov 18 at 20:16






you should use data:$(form).serialize() simply rather than using FormData until unless you are planning to upload files along with the form using ajax. @TomaTomov
– Muhammad Omer Aslam
Nov 18 at 20:16














up vote
1
down vote













URL in JavaScript seems to be not fully specified.



The valid way would be:



url: 'index.php?r=site/send-contact',


But this works only if your index.php is in root folder.



To make it work with any situation (e.g., index.php is not in root), then you have different solutions. I personally like to use this:




  • Declare action and id in your form:


Example:



$form = ActiveForm::begin([
'action' => ['site/send-contact'],
'id' => 'my-form',
]);



  • Use a link (that is generated by Yii2 itself) in your JS code:


Example:



$('#home-contact').on('beforeSubmit', function() {
$.ajax({
method: 'post',
url: $('#my-form').attr('action'),
data: new FormData($(this))[0],
success: function(data) {
console.log(data)
}
});

return false;
});


This should work in all cases, whenever your files are.



Hope that helps!






share|improve this answer





















  • whats with new FormData($(this))[0] ? this will give undefined
    – Muhammad Omer Aslam
    Nov 20 at 1:31












  • I used what OP gave in a question. I was looking only at url: part here.
    – Gytis Tenovimas
    Nov 20 at 12:09















up vote
1
down vote













URL in JavaScript seems to be not fully specified.



The valid way would be:



url: 'index.php?r=site/send-contact',


But this works only if your index.php is in root folder.



To make it work with any situation (e.g., index.php is not in root), then you have different solutions. I personally like to use this:




  • Declare action and id in your form:


Example:



$form = ActiveForm::begin([
'action' => ['site/send-contact'],
'id' => 'my-form',
]);



  • Use a link (that is generated by Yii2 itself) in your JS code:


Example:



$('#home-contact').on('beforeSubmit', function() {
$.ajax({
method: 'post',
url: $('#my-form').attr('action'),
data: new FormData($(this))[0],
success: function(data) {
console.log(data)
}
});

return false;
});


This should work in all cases, whenever your files are.



Hope that helps!






share|improve this answer





















  • whats with new FormData($(this))[0] ? this will give undefined
    – Muhammad Omer Aslam
    Nov 20 at 1:31












  • I used what OP gave in a question. I was looking only at url: part here.
    – Gytis Tenovimas
    Nov 20 at 12:09













up vote
1
down vote










up vote
1
down vote









URL in JavaScript seems to be not fully specified.



The valid way would be:



url: 'index.php?r=site/send-contact',


But this works only if your index.php is in root folder.



To make it work with any situation (e.g., index.php is not in root), then you have different solutions. I personally like to use this:




  • Declare action and id in your form:


Example:



$form = ActiveForm::begin([
'action' => ['site/send-contact'],
'id' => 'my-form',
]);



  • Use a link (that is generated by Yii2 itself) in your JS code:


Example:



$('#home-contact').on('beforeSubmit', function() {
$.ajax({
method: 'post',
url: $('#my-form').attr('action'),
data: new FormData($(this))[0],
success: function(data) {
console.log(data)
}
});

return false;
});


This should work in all cases, whenever your files are.



Hope that helps!






share|improve this answer












URL in JavaScript seems to be not fully specified.



The valid way would be:



url: 'index.php?r=site/send-contact',


But this works only if your index.php is in root folder.



To make it work with any situation (e.g., index.php is not in root), then you have different solutions. I personally like to use this:




  • Declare action and id in your form:


Example:



$form = ActiveForm::begin([
'action' => ['site/send-contact'],
'id' => 'my-form',
]);



  • Use a link (that is generated by Yii2 itself) in your JS code:


Example:



$('#home-contact').on('beforeSubmit', function() {
$.ajax({
method: 'post',
url: $('#my-form').attr('action'),
data: new FormData($(this))[0],
success: function(data) {
console.log(data)
}
});

return false;
});


This should work in all cases, whenever your files are.



Hope that helps!







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 18 at 14:18









Gytis Tenovimas

8,218112546




8,218112546












  • whats with new FormData($(this))[0] ? this will give undefined
    – Muhammad Omer Aslam
    Nov 20 at 1:31












  • I used what OP gave in a question. I was looking only at url: part here.
    – Gytis Tenovimas
    Nov 20 at 12:09


















  • whats with new FormData($(this))[0] ? this will give undefined
    – Muhammad Omer Aslam
    Nov 20 at 1:31












  • I used what OP gave in a question. I was looking only at url: part here.
    – Gytis Tenovimas
    Nov 20 at 12:09
















whats with new FormData($(this))[0] ? this will give undefined
– Muhammad Omer Aslam
Nov 20 at 1:31






whats with new FormData($(this))[0] ? this will give undefined
– Muhammad Omer Aslam
Nov 20 at 1:31














I used what OP gave in a question. I was looking only at url: part here.
– Gytis Tenovimas
Nov 20 at 12:09




I used what OP gave in a question. I was looking only at url: part here.
– Gytis Tenovimas
Nov 20 at 12:09










up vote
-1
down vote













did you add 'enableAjaxValidation' => true or add action name in active form?



$form = ActiveForm::begin([
'action' => ['controller/action'],
'enableAjaxValidation' => true
]);





share|improve this answer

















  • 2




    Why do I need to enable it when I am sending the AJAX request by myself ?
    – Toma Tomov
    Nov 17 at 21:06










  • yeah sorry, add a complete route in your URL in JS file @TomaTomov
    – Mehran
    Nov 18 at 5:34












  • ajax validation has nothing to do with it
    – Muhammad Omer Aslam
    Nov 18 at 12:47















up vote
-1
down vote













did you add 'enableAjaxValidation' => true or add action name in active form?



$form = ActiveForm::begin([
'action' => ['controller/action'],
'enableAjaxValidation' => true
]);





share|improve this answer

















  • 2




    Why do I need to enable it when I am sending the AJAX request by myself ?
    – Toma Tomov
    Nov 17 at 21:06










  • yeah sorry, add a complete route in your URL in JS file @TomaTomov
    – Mehran
    Nov 18 at 5:34












  • ajax validation has nothing to do with it
    – Muhammad Omer Aslam
    Nov 18 at 12:47













up vote
-1
down vote










up vote
-1
down vote









did you add 'enableAjaxValidation' => true or add action name in active form?



$form = ActiveForm::begin([
'action' => ['controller/action'],
'enableAjaxValidation' => true
]);





share|improve this answer












did you add 'enableAjaxValidation' => true or add action name in active form?



$form = ActiveForm::begin([
'action' => ['controller/action'],
'enableAjaxValidation' => true
]);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 at 20:57









Mehran

9429




9429








  • 2




    Why do I need to enable it when I am sending the AJAX request by myself ?
    – Toma Tomov
    Nov 17 at 21:06










  • yeah sorry, add a complete route in your URL in JS file @TomaTomov
    – Mehran
    Nov 18 at 5:34












  • ajax validation has nothing to do with it
    – Muhammad Omer Aslam
    Nov 18 at 12:47














  • 2




    Why do I need to enable it when I am sending the AJAX request by myself ?
    – Toma Tomov
    Nov 17 at 21:06










  • yeah sorry, add a complete route in your URL in JS file @TomaTomov
    – Mehran
    Nov 18 at 5:34












  • ajax validation has nothing to do with it
    – Muhammad Omer Aslam
    Nov 18 at 12:47








2




2




Why do I need to enable it when I am sending the AJAX request by myself ?
– Toma Tomov
Nov 17 at 21:06




Why do I need to enable it when I am sending the AJAX request by myself ?
– Toma Tomov
Nov 17 at 21:06












yeah sorry, add a complete route in your URL in JS file @TomaTomov
– Mehran
Nov 18 at 5:34






yeah sorry, add a complete route in your URL in JS file @TomaTomov
– Mehran
Nov 18 at 5:34














ajax validation has nothing to do with it
– Muhammad Omer Aslam
Nov 18 at 12:47




ajax validation has nothing to do with it
– Muhammad Omer Aslam
Nov 18 at 12:47


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355009%2faction-not-found-after-ajax-request%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

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga