Php jQuery如何引用目录$.post()
欢迎光临 如何将script.js文件引用到index.php 在script.js中:Php jQuery如何引用目录$.post(),php,jquery,Php,Jquery,欢迎光临 如何将script.js文件引用到index.php 在script.js中: $.post('../php/index.php', {data}); 结构目录: js/ script.js php/ index.php index.html 在控制台中返回我: 404(未找到)无法发布/php/index.php 只需完整使用文件位置,如: $.post('http://www.example.com/directory/php/index.php', {data});
$.post('../php/index.php', {data});
结构目录:
js/
script.js
php/
index.php
index.html
在控制台中返回我:
404(未找到)无法发布/php/index.php
只需完整使用文件位置,如:
$.post('http://www.example.com/directory/php/index.php', {data});
只需完整使用文件位置,如:
$.post('http://www.example.com/directory/php/index.php', {data});
javascript中的url必须与web浏览器中的当前活动url相对。解决此问题的最佳方法是使用绝对路径。像这样:
$.post('/php/index.php', {data});
javascript中的url必须与web浏览器中的当前活动url相对。解决此问题的最佳方法是使用绝对路径。像这样:
$.post('/php/index.php', {data});
$.post调用将来自index.html位置。因此,将script.js更新为:
$.post('php/index.php',{data})代码>谢谢@daveyWavey它正在运行$。post调用将来自index.html位置。因此,将script.js更新为:$.post('php/index.php',{data})
Thank@daveyWavey它正在工作,这意味着如果你移动到另一个域,你需要更新所有的js,虽然是的,但考虑到js文件也可以移动,这仍然是一个很好的方法:)我通过在所有页面的标题部分设置一个名为site
的变量(例如var site="http://www.example.com";
,然后对FQDN的任何引用都会使用此选项。网站是由PHP添加到页面的&反映当前URL,因此如果网站移动,该值会自动更新。这意味着如果移动到其他域,您将需要更新所有js,虽然是的,但考虑到js文件也可以是mo,这仍然是一种很好的方法ved:)我在所有页面的标题部分都有一个名为site
的变量(例如var site=”http://www.example.com“;
,对FQDN的任何引用都将使用此选项。PHP会将站点添加到页面中,并反映当前URL,因此如果站点移动,该值会自动更新