AJAX Trouble

konekt

New Member
Messages
100
Reaction score
0
Points
0
Important thing to note: the following codes are to be called from a firefox extension that I am working on.



With the following Javascript code, I get this error:

Error: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: http://konekt.x10hosting.com/konekt.js :: wut :: line 7" data: no]
Source File: http://konekt.x10hosting.com/konekt.js
Line: 7

The code is like this:

Code:
var http = new XMLHttpRequest();

function wut(event)
{
http.open("GET", "register.php?user=emin&pass=dud", true);
http.onreadystatechange = useHttpResponse;
http.send(null);

}

function useHttpResponse()
{
if(http.readyState == 4)
{
alert(http.readystate);
alert("OMG IT WORKS!!!");
}

}

var button = document.getElementById("norm");
button.addEventListener('command', wut, true);

I am trying to call the .js file from my localhost, however, the .js and .php are on the same sever (same folder too), so I shouldn't be getting a permission error. I'm not sure what the problem is.

Another interesting thing is that if I press the button twice, I'll get the "OMG!! IT WORKS!" but the register.php will not have done anything.

EDIT:
Ok, it seems like this is telling me the file is not found. However, when I try to give it a more specific path like:

http://konekt.x10hosting.com/register.php?etc...

I get a permission error -_-
 
Last edited:

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
even though they are in the same folder, they may not have the same permissions, check on the permissions level that it is 755 (should be the right code)
 

konekt

New Member
Messages
100
Reaction score
0
Points
0
I gave that a shot and this is the error I am getting:
Error: [Exception... "'Permission denied to call method XMLHttpRequest.open' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]

Researching it, i found out that it is a security feature of AJAX to prevent people from accessing scripts on another domain. This shouldn't be the case however. This is how my call order goes:

.xul file on localhost connects to .js on my server which uses XMLHttpRequest to access a .php file in the same folder with the same permissions. I'm a little lost as to where to go from here.

Edit:
SOLUTION: The errors thrown came from a security feature within the browsers that prevented localhost from calling server-side scripts dynamically even if they were in the same location.

For me, this was solved by the fact that I am writing a Firefox extension which comes with innate workarounds; thus, if one is making a Firefox extension and having problems with ajax they need to install the extension fully (or in-development phase) to be able to use the workaround that comes with the extension and allows connection to scripts that dynamically call scripts on the same server.

If one is having the same issues and is simply coding a website, there are a few workarounds floating about. The first assumes the scripts are not in the same file and requires clien-side changes, the others use location.host to solve it.
 
Last edited:
Top