The answer from the comment on the question:
Got solution to my problem. XMLHTTPRequest.status returns 0 and responseText is blank in FireFox 3.5
It was only due to the fact that I was using absolute path. Using relative path solved my problem.
Excellent!
As for your additional question:
However, I'm still confused with the fact that I've to use relative path like this: index/index.php in the path attribute of the script file residing in the index directory itself. Why? I mean, simply using 'index.php' should have solved the problem, isn't it?
As I understood it, you have your HTML at http://example.org/test.html with
<script src="subdir/main.js>
...which resolves to http://example.org/subdir/main.js, which calls XMLHttpRequest:
xhr.open("POST", "index.php", true);
This requests http://example.org/index.php, not http://example.org/subdir/index.php
This is because the relative URLs in XMLHttpRequest (as in many other cases) are resolved against the document's base URL, not the script's URL.
If the relative URLs were resolved against script's URL it might turn out very confusing: Imagine you have jQuery at /lib/jquery.js
, which calls XMLHttpRequest and your own code at /main.js
calling jQuery.ajax(... "data.txt" ...) . Should this request /data.txt
or lib/data.txt
?