Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining relative path with jQuery

I have several wordpress sites installed in subfolders under a top level domain:

  1. http://www.mydomain.com/site-a/
  2. http://www.mydomain.com/site-b/

I need to load an AJAX file in each of them, and I've used the following code:

// Initiate asynchronous load of xml data: jQuery.ajax({     type: "GET",     url: "/wp-content/themes/mytheme/data.xml",     dataType: "xml",     success: parseDataXML }); 

but that ends up searching for the file in the domain's root path:

http://www.mydomain.com/wp-content/themes/mytheme/data.xml 

Instead of the site's root path:

http://www.mydomain.com/site-a/wp-content/themes/mytheme/data.xml 
like image 968
Yarin Avatar asked Jun 08 '11 17:06

Yarin


1 Answers

Get rid of the leading "/" in the url path. The leading slash means "from the root of the site", not "from my current folder".

Edit: Ok, then in the root index of each "site", you need to define BASE HREF to include that folder name. Then the leading slash should take into account that value instead of the site root.

like image 140
Adrian J. Moreno Avatar answered Sep 24 '22 17:09

Adrian J. Moreno