0

Hy again! =)

Here's my problem. My AJAX doesn't want to work, and Firebug gives me this error message: "uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.setRequestHeader]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: [url]http://localhost/mysite/js/functions.js[/url] :: callSaveFile :: line 273" data: no]".

So as u see I'm using a POST method to send data to a PHP file, but I'm pretty new to POST method... If someone could help me with this would be really fine! =)

var url="open.php";
	var params="filename="+document.getElementById("filename").value;
	params=params+"&extension="+document.getElementById("extension").value;
	params=params+"&content="+content;
	params=params+"&path="+document.getElementById("path").value;
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", content.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=saveStateChanged;
	xmlhttp.open("POST",url,true);
	xmlhttp.send(params);

Thank you! =)

Edited by benqus: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Airshow
0

Benkus,

Try this :

var url = "open.php";
	var params = [
		"filename=" + document.getElementById("filename").value,
		"extension=" + document.getElementById("extension").value,
		"content=" + content,
		"path=" + document.getElementById("path").value
	].join('&');//tidier
	xmlhttp.open("POST",url,true);//moved up
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange = saveStateChanged;
	xmlhttp.send(params);

You'll see I have deleted two setRequestHeader lines. "Connection", "close"; is wrong if you want to receive a response back from the server, and "Content-length", content.length; is only necessary if you want to force "Connection", "close"; . Read more here (5th paragraph).

That should give it a chance.

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.