jQuery的阿贾克斯URL路径问题 [英] Jquery Ajax url path Issue
问题描述
我想设计一个信息系统,为我的网站,但我不能让我的AJAX运行。 所以我使文件之间的相互作用的简化版本。
I am trying to design a message system for my website, but i can't get my ajax running. So I make a simpler version of the interaction between the files.
下面是我的文件中有test.php的和load.php下的根文件夹(的public_html)的。
Here is my file both test.php and load.php is under the root folder ( public_html).
我在test.php的ajax的功能。 load.php只是简单地附和哇。
i have the ajax function in test.php. load.php is just simply echoing "wow".
$("#test").click(function(){
alert("Clicked.");
$.ajax({
url:"/load.php",
type:"POST",
beforeSend: function(){
alert("testing");
},
success:function(result){
$("#result").html(result);
alert(" sss "+result);
}
}).error(function(){alert("wrong");});
});
现在它完美。
...........如何设置相对路径...................
下面是更复杂的设计
3个文件,都在不同的文件夹:
3 files, all in different folder :
- messages.php(下根)
- 显示所有邮件
- messages.php (under root)
- showing all the messages
- 在一个小组将包括在messages.php
- control.php将使用AJAX调用它,然后显示结果control.php
所以当messages.php用户负载,它会加载control.php然后运行AJAX调用control.php。
so when user load in messages.php, it will load control.php then run the ajax call control.php.
我很困惑如何设置这些路径阿贾克斯
(在messages.php包括control.php正常工作)
I am so confused about how to set up these paths for ajax
( including control.php in messages.php works fine)
感谢
推荐答案
如果你想联系的文件都在根目录,你可以使用 / [文件]的.php
所以,无论你是在道路上的页面将是正确的。这听起来像你有一个相对路径的问题。你在控制台中得到任何错误?
If the files you're trying to contact are in the root you can use /[file].php
so that no matter which page you're on the path will be correct. It sounds like you have a relative path issue. Do you get any errors in the console?
这篇关于jQuery的阿贾克斯URL路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!