Jump to content

Giving dynamic path inside a module when ajax is being loaded


Recommended Posts

Hi,

I am doing a small module in prestashop. As per the requirment of the module I need ajax. For ajaxI used jQuery ajax.So to do that I made my code something like this

 



function selectCountry() {
  var state = $('#country').val();
  //console.log(state);
  $.ajax({
    type: "GET",
    url: "http://localhost/WebSites/Prestashop/modules/mymodule/selectstate.php",
    cache: false,
    data: { sta : state },
    success: function(html) {
      $(".city").html(html);
    }
  });
}


 

Now here I have a query. You can see in url I am doing path in hard coded


(url: "http://localhost/WebSites/Prestashop/modules/mymodule/selectstate.php").


Here its fine but what about the url. As it is hard-coded it will work only on my system. I want to know how to make it a dynamic path. So that if someone will install the module he will get the module working. Any help and suggestions will be really appreciable.

Link to comment
Share on other sites

You can use ther baseDir variable, which is assigned in the header.tpl file, and is accessible on all embedded javascript. It points to the main site url. Therefore you can use it like this:

 url: baseDir + "/modules/mymodule/selectstate.php",
  • Like 1
Link to comment
Share on other sites

 

You can use ther baseDir variable, which is assigned in the header.tpl file, and is accessible on all embedded javascript. It points to the main site url. Therefore you can use it like this:

 url: baseDir + "/modules/mymodule/selectstate.php",

so shall I assign baseDir in my .tpl file or it is by default assigned in prestashop?

Link to comment
Share on other sites

×
×
  • Create New...