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! =)

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.