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 3


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, enter image description here

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
  • I have not succeeded, but I made a block
    – St3phan
    Nov 15, 2016 at 19:44
  • try window.baseUrl. Nov 16, 2016 at 5:08
  • 2
    or try window.BASE_URL Nov 16, 2016 at 5:21
  • is there any other way for same ? Sep 28, 2019 at 5:57

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
    – St3phan
    Nov 11, 2016 at 20:08
  • magento.stackexchange.com/questions/123819/… This may help you. Nov 12, 2016 at 5:42
  • 1
    i 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

kindly check here it will works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.