How to make ajax call in magento admin form
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
1
down vote
favorite
In my magento admin form, I have added a category field. Based on the selection of category in category field an ajax call should be done.
$category = $fieldSet->addField(
'category_id', 'select', [
'name' => 'category_id',
'label' => __('Category'),
'required' => true,
'values' => $this->_selectedCategories->toOptionArray(),
]
);
I have set ajax call for that field
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl');
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
Now how to set url for ajax call?
url: '<?= $url; ?>'
I am not getting controller call using this line. How to set $url as a ajax call url in script?
magento2
add a comment |
up vote
1
down vote
favorite
In my magento admin form, I have added a category field. Based on the selection of category in category field an ajax call should be done.
$category = $fieldSet->addField(
'category_id', 'select', [
'name' => 'category_id',
'label' => __('Category'),
'required' => true,
'values' => $this->_selectedCategories->toOptionArray(),
]
);
I have set ajax call for that field
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl');
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
Now how to set url for ajax call?
url: '<?= $url; ?>'
I am not getting controller call using this line. How to set $url as a ajax call url in script?
magento2
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
In my magento admin form, I have added a category field. Based on the selection of category in category field an ajax call should be done.
$category = $fieldSet->addField(
'category_id', 'select', [
'name' => 'category_id',
'label' => __('Category'),
'required' => true,
'values' => $this->_selectedCategories->toOptionArray(),
]
);
I have set ajax call for that field
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl');
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
Now how to set url for ajax call?
url: '<?= $url; ?>'
I am not getting controller call using this line. How to set $url as a ajax call url in script?
magento2
In my magento admin form, I have added a category field. Based on the selection of category in category field an ajax call should be done.
$category = $fieldSet->addField(
'category_id', 'select', [
'name' => 'category_id',
'label' => __('Category'),
'required' => true,
'values' => $this->_selectedCategories->toOptionArray(),
]
);
I have set ajax call for that field
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl');
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
Now how to set url for ajax call?
url: '<?= $url; ?>'
I am not getting controller call using this line. How to set $url as a ajax call url in script?
magento2
magento2
edited yesterday
Milind Singh
16810
16810
asked yesterday
Pavitra
1048
1048
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
4
down vote
accepted
- Your URL should not have a session key. Remove as below.
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl', ['_nosid' => true]);
- Correct the way to add a variable in the string.
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
1
Its Working !!!. Thank you.
– Pavitra
yesterday
add a comment |
up vote
2
down vote
Try to use this below way :
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: url,
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
add a comment |
up vote
0
down vote
You can get URL using below code.
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
- Your URL should not have a session key. Remove as below.
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl', ['_nosid' => true]);
- Correct the way to add a variable in the string.
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
1
Its Working !!!. Thank you.
– Pavitra
yesterday
add a comment |
up vote
4
down vote
accepted
- Your URL should not have a session key. Remove as below.
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl', ['_nosid' => true]);
- Correct the way to add a variable in the string.
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
1
Its Working !!!. Thank you.
– Pavitra
yesterday
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
- Your URL should not have a session key. Remove as below.
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl', ['_nosid' => true]);
- Correct the way to add a variable in the string.
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
- Your URL should not have a session key. Remove as below.
$url = $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl', ['_nosid' => true]);
- Correct the way to add a variable in the string.
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: ''.$url.'',
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
answered yesterday
Milind Singh
16810
16810
1
Its Working !!!. Thank you.
– Pavitra
yesterday
add a comment |
1
Its Working !!!. Thank you.
– Pavitra
yesterday
1
1
Its Working !!!. Thank you.
– Pavitra
yesterday
Its Working !!!. Thank you.
– Pavitra
yesterday
add a comment |
up vote
2
down vote
Try to use this below way :
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: url,
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
add a comment |
up vote
2
down vote
Try to use this below way :
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: url,
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
add a comment |
up vote
2
down vote
up vote
2
down vote
Try to use this below way :
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: url,
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
Try to use this below way :
$category->setAfterElementHtml('
<script>
require(['jquery'], function($){
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
var customUrl =
$("#category_id").on('change', function () {
$.ajax({
url: url,
type: 'POST',
data: {category_id: $(this).val(), form_key: window.FORM_KEY},
success: function (response) {
$("#url").val(response['content']);
}
});
});
});
</script>
');
answered yesterday
Emipro Technologies Pvt. Ltd.
2,2821723
2,2821723
add a comment |
add a comment |
up vote
0
down vote
You can get URL using below code.
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
add a comment |
up vote
0
down vote
You can get URL using below code.
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
add a comment |
up vote
0
down vote
up vote
0
down vote
You can get URL using below code.
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
You can get URL using below code.
var url = '" . $this->_urlInterface->getUrl('homepage/ajax/getcategoryurl') . "';
edited yesterday
answered yesterday
Kishan Patadia
3,4271923
3,4271923
add a comment |
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%2fmagento.stackexchange.com%2fquestions%2f250730%2fhow-to-make-ajax-call-in-magento-admin-form%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