how to get the base url in javascript

前端 未结 10 1855
一整个雨季
一整个雨季 2020-12-01 04:12

I am building a website with CodeIgniter, I have various resources that I load with the base_url helper function like this

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 04:38

    You can make PHP and JavaScript work together by generating the following line in each page template:

    
    

    Then you can refer to document.mybaseurl anywhere in your JavaScript. This saves you some debugging and complexity because this variable is always consistent with the PHP calculation.

提交回复
热议问题