Cakephp - getting the correct path in javascript file

I am trying to use the jQuery $ .post () call in the javascript file that I have in the webroot / js folder.

The javascript file is called in several places, and I'm struggling to figure out which correct path to use.

I am using the following at the moment

$.post("../../spanners/deleteSpanner", function(data) { alert(data); }); 

But obviously, using ../../ will not work in certain parts of the application.

What can I replace ../../ with?

+4
source share
2 answers

It depends on the location of your application on your server and how the key manager works. Assume the following:

 mywebsite.com/spanners/deleteSpanner ===> $.post("/spanners/deleteSpanner"... mywebsite.com/someApp/spanners/deleteSpanner ===> $.post("/someApp/spanners/deleteSpanner"... 

To prove this to you, check out this demo: http://jsbin.com/APejeQa/1 , where you could access src on the jsbin logo website. any page level, just starting your way with /

 <img src="/images/jsbin_static.png" alt="jsbin logo" /> 
0
source

in your view view file above:

 echo $javascript->link('spanners/deletespanners'); 
0
source

Source: https://habr.com/ru/post/1500411/


All Articles