jquery - Javascript get real path in any situation ($.ajax) -
my project has following structure:
sil -> css -> js -> clients -> index.php -> response.php index.php
my problem on folder clients.
my url can have multiple choices, of them are:
http://localhost/sil/clients/ http://localhost/sil/clients/all/ http://localhost/sil/clients/stackoverflow/2 http://localhost/sil/clients/stackoverflow/2/technology/5
as can see use .htaccess
write rules.
that said, problem here url inside $.ajax.
. use following code inside clients/index.php
file.
$.ajax({ url : 'response.php?type=add', });
this code works if , if url http://localhost/sil/clients/
.
in case url other options said above, won't work, because file url output be:
http://localhost/sil/clients/all/response.php?type=add
which wrong.
i have solved issue using complete url, not believe best approach since when have upload files server ftp have change in every $.ajax
localhost
domain name.
$.ajax({ url : 'http://localhost/sil/response.php?type=add', });
what other options have? i've tried, without success, window.location.pathname
.
you can either start url slash in order specify "root directory":
$.ajax({ url : '/sil/clients/response.php?type=add', });
or use <base>
tag in html:
<base href="http://localhost/sil/clients/" /> <script> $.ajax({ url : 'response.php?type=add', }); </script>
Comments
Post a Comment