How get admin url in js file ? Js file call AjaxController and this Js file are called to System -> Config from system.xml
3 Answers
You can try this this.values.baseUrl;
in your js and you can also refer /var/www/html/magento2/vendor/magento/magento2-base/lib/web/mage/app/config.js
When you see admin page view source,
you have admin base url, so you can get this base url using window.values.BASE_URL
or may be window.BASE_URL
.
-
have you tried this 'this.values.baseUrl;'? check my updated answer. Nov 14, 2016 at 4:54
-
-
-
2
-
You can use php code to get AjaxUrl :
var requestUrl = <?php $this->getUrl("..."); ?>
-
I need in JS file not phtml file, I don't have a phtml file in my case– St3phanNov 11, 2016 at 20:08
-
-
1i want to direct get in js file ... i try to use mage/url but that not working in admin Sep 28, 2019 at 5:58
-
@NavinBhudiya you can place this php url into some html tag and then can retrieve that url in js file or you can use knockout way. add your url into knockout string and retrieve it in js file and use it Sep 30, 2019 at 8:51