php - CakePHP and Ajax request url -


I am currently using AJAX in many controllers in my application. I have implemented AJAX functionality using the jQuery supported version.

  $ Ajax ({url: 'getCountries', type: "post", data type: "html", data: "data =" + result, success: function (data) {// magic ...}}});   

As you can see from the code above the URL of this request, 'getcountries' means that if the request

  http: / / localhost / appname / controllername / methodname   

so the url request the

  http: // localhost / appname / controllername / getcountries   

However, if you are different than the example above URL using this script, I

  http: // localhost / appname / controllername / methodname / 7   

(such as in editing view), then those URAs The Ajax call request URL will change

  http: // localhost / appname / controllername / methodname / getcountries   

how do I create it myself so request URLs can be automatically dependent. At present I'm on the controller?

Please note that the URL path has the name of the root folder of the appname application and it should also be included so that the files will be moved to a different server / location. Links will be compatible with the root folder

Try this one

  $ .ajax ({url: "& lt ;? php echo $ this-> webroot $ this-> parameter [" controller "];? & Gt; / yourAction"});   

$ this-> The webroot for example includes paths on your webstrot if your app folder is htdocs / test and you localhost / test / $ this- & gt;

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -