XMLHttpRequest对象的打开方法的相对路径 [英] relative path for open method of a XMLHttpRequest object

查看:46
本文介绍了XMLHttpRequest对象的打开方法的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在包含Ajax请求的JavaScript文件中,URL相对于什么?我有包含目录alpha和bravo的www目录.包含alpha的JavaScript文件和包含该文件的HTML文件,以及以出色的方式处理请求的PHP.

In the JavaScript file containing the Ajax request what is the URL relative to? I've got the www directory containing the directories alpha and bravo. The JavaScript file in alpha and the HTML file that includes it and the PHP that processes the request in bravo.

在JavaScript文件中,我有 xmlhttp.open("GET","CheckServer.php?name =" + name,true); ;但是我不认为 CheckServer.php是正确的.我已经尝试过 ../bravo/CheckServer.php ,但是它不起作用.

In the JavaScript file I have xmlhttp.open("GET", "CheckServer.php?name="+name,true); but I don't think CheckServer.php is right. I've tried ../bravo/CheckServer.php but it doesn't work.

我没有使用JQuery,而是在使用WAMP.

I'm not using JQuery and I am using WAMP.

另外,我可以使用任何故障排除工具来查看是否首先访问了用于处理请求的PHP页面?

Plus, is there any trouble shooting tools I can use to see if the PHP page for processing the request is being accessed in the first place?

我打开了控制台,它说我在JavaScript文件中调用的函数未定义.仅当我将.js文件移动到其他目录时,才会发生这种情况.(我适当地修改了< script> 标记:< script type ="text/javascript" src ="../alpha/Check.js"> .

I opened the console and it says the function I'm calling in the JavaScript file is not defined. This only happens when I moved the .js file to a different directory. (I modified the <script> tag appropiratly: <script type="text/javascript" src="../alpha/Check.js">.

我认为WAMP存在问题,因为我将完全相同的文件/文件夹复制到了桌面,并且一切正常.

EDIT 2: I think there is a problem with WAMP because I copy the exact same files/folders to the desktop and everything works.

推荐答案

它是相对的,基于它被调用的页面的当前位置.它与从何处加载JavaScript无关.

It is relative based on the current location of the page it is called on. It has nothing to do with where the JavaScript is loaded from.

打开控制台,查看Ajax请求[控制台或网络选项卡],您将看到它所请求的路径.

Open up the console and look at the Ajax request [console or net tab], you will see the path that it is requesting.

这篇关于XMLHttpRequest对象的打开方法的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆