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!
yii2 yii2-advanced-app
add a comment |
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!
yii2 yii2-advanced-app
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 usingnew FormData()
instead ?
– Muhammad Omer Aslam
Nov 18 at 13:23
add a comment |
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!
yii2 yii2-advanced-app
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
yii2 yii2-advanced-app
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 usingnew FormData()
instead ?
– Muhammad Omer Aslam
Nov 18 at 13:23
add a comment |
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 usingnew 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
add a comment |
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.
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 thecontetnType
andprocessData
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 usedata:$(form).serialize()
simply rather than usingFormData
until unless you are planning to upload files along with the form using ajax. @TomaTomov
– Muhammad Omer Aslam
Nov 18 at 20:16
add a comment |
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
andid
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!
whats withnew FormData($(this))[0]
? this will giveundefined
– Muhammad Omer Aslam
Nov 20 at 1:31
I used what OP gave in a question. I was looking only aturl:
part here.
– Gytis Tenovimas
Nov 20 at 12:09
add a comment |
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
]);
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
add a comment |
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.
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 thecontetnType
andprocessData
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 usedata:$(form).serialize()
simply rather than usingFormData
until unless you are planning to upload files along with the form using ajax. @TomaTomov
– Muhammad Omer Aslam
Nov 18 at 20:16
add a comment |
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.
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 thecontetnType
andprocessData
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 usedata:$(form).serialize()
simply rather than usingFormData
until unless you are planning to upload files along with the form using ajax. @TomaTomov
– Muhammad Omer Aslam
Nov 18 at 20:16
add a comment |
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.
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.
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 thecontetnType
andprocessData
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 usedata:$(form).serialize()
simply rather than usingFormData
until unless you are planning to upload files along with the form using ajax. @TomaTomov
– Muhammad Omer Aslam
Nov 18 at 20:16
add a comment |
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 thecontetnType
andprocessData
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 usedata:$(form).serialize()
simply rather than usingFormData
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
add a comment |
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
andid
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!
whats withnew FormData($(this))[0]
? this will giveundefined
– Muhammad Omer Aslam
Nov 20 at 1:31
I used what OP gave in a question. I was looking only aturl:
part here.
– Gytis Tenovimas
Nov 20 at 12:09
add a comment |
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
andid
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!
whats withnew FormData($(this))[0]
? this will giveundefined
– Muhammad Omer Aslam
Nov 20 at 1:31
I used what OP gave in a question. I was looking only aturl:
part here.
– Gytis Tenovimas
Nov 20 at 12:09
add a comment |
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
andid
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!
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
andid
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!
answered Nov 18 at 14:18
Gytis Tenovimas
8,218112546
8,218112546
whats withnew FormData($(this))[0]
? this will giveundefined
– Muhammad Omer Aslam
Nov 20 at 1:31
I used what OP gave in a question. I was looking only aturl:
part here.
– Gytis Tenovimas
Nov 20 at 12:09
add a comment |
whats withnew FormData($(this))[0]
? this will giveundefined
– Muhammad Omer Aslam
Nov 20 at 1:31
I used what OP gave in a question. I was looking only aturl:
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
add a comment |
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
]);
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
add a comment |
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
]);
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
add a comment |
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
]);
did you add 'enableAjaxValidation' => true
or add action name in active form?
$form = ActiveForm::begin([
'action' => ['controller/action'],
'enableAjaxValidation' => true
]);
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
add a comment |
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
add a comment |
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%2f53355009%2faction-not-found-after-ajax-request%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
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 usingnew FormData()
instead ?– Muhammad Omer Aslam
Nov 18 at 13:23