Relative path for the public method of the XMLHttpRequest object

In the JavaScript file containing the Ajax request, what does the URL refer to? I have a www directory containing the alpha and bravo directories. JavaScript file in alpha and the HTML file that includes it, and PHP processing the request in bravo.

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

I do not use jQuery and I use WAMP.

Plus, are there any troubleshooting tools I can use to see if I primarily access the PHP page to process the request?

EDIT: I opened the console and it says that the function I call in the JavaScript file is not defined. This only happens when I moved the .js file to another directory. (I modified the <script> : <script type="text/javascript" src="../alpha/Check.js"> .

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

+4
source share
2 answers

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

Open the console and look at the Ajax request [console or network tab], you will see the path that it requests.

+6
source

This is a URL that has nothing to do with directories. They can be mapped to directories on the server, and often this happens, but the client cannot know this for sure and does not care. URL refers to the current URL (what you see in the address bar of the browser).

So, the question is not where "CheckServer.php" is located on the server ", but" how can I access it from the client ".

If you like it:

 http://example.com/alpha/index.html http://example.com/bravo/CheckServer.php 

well. Use a relative URL.

But if so:

 http://alpha.example.com/index.html http://bravo.example.com/CheckServer.php 

then it becomes complicated. You will need to learn CORS (Cross-Origin resource sharing), since AJAX usually does not work across domains.

Oh, and if CheckServer.php is not available at all ... you can probably imagine the answer.

0
source

All Articles