best practice to use action url while calling ajax in cakePHP

后端 未结 5 1377
失恋的感觉
失恋的感觉 2020-12-28 11:00

I am using ajax with jQuery in my cakePHP application.
and my javascript function is placed inside a javascript file.

now in my local system the files are kept

5条回答
  •  旧时难觅i
    2020-12-28 11:45

    I'm updating Paul Dragoonis's answer to reflect the latest CakePHP version (2.2).

    In your layout file, set the JavaScript variable with CakePHP's JSHelper: Js->set('url', $this->request->base); ?>, where $this->request is an instance of CakeRequest and gives information on the current request.

    After the line above, write the buffer with Js->writeBuffer(); ?>.

    Then, you can access this variable in JavaScript with app.url.

提交回复
热议问题