2

What is the code for going up one level in javascript? I'm using Ajax.

var ajax = new XMLHttpRequest();
ajax.open("POST", "goUpOneLevel/php/mail.php", true);

Like in CSS, while setting background URL, to go up one level we use '../' But in the above code this is not working.

Please tell me the code to go up one level.

I think this much of code is enough for this question that's why I am not posting whole bunch of my code. AND I know I can use absolute url, but I want relative url because if my code is shifted to another domain (which will 100%) then it will not work.

Here is my list of URLs -
My JS file in which the ajax code is placed-
http://localhost/myFolder/js/script.js

My php file - http://localhost/myFolder/php/mail.php

Thanks in advance.

Rohit Kumar
  • 2,048
  • 1
  • 14
  • 28
  • Did you even try `../`? – Joseph Jun 14 '15 at 13:24
  • yes I tried, ajax.open("POST", "../php/mail.php", true); is not working for me, but when I change it to ajax.open("POST", "http : //localhost/php/mail.php", true); it works fully. – Rohit Kumar Jun 14 '15 at 13:27
  • 2
    Your path is relative to the current web URL and NOT the .js file location. It would help if you would provide us with the URL of the page you are trying to run this on. And for *going one level up*, the `../` *must* work. Provided you *can* go one level up. – alesc Jun 14 '15 at 13:37
  • okay done the edits you wanted. – Rohit Kumar Jun 14 '15 at 13:54
  • JavaScript paths are relative to the HTML file. Have you tried just `"mail.php"` or `"php/mail.php"` depending on where the HTML file is? – JJJ Jun 14 '15 at 13:55
  • yes worked!!, `"php/mail.php"` worked for me.. Thank you. and post it as the answer.. – Rohit Kumar Jun 14 '15 at 14:08

0 Answers0