tags:

views:

51

answers:

2

Hi,

Well I hoped everything would work fine finally. But of course it doesn't. The new problem is the following message:

Request-URI Too Large The requested URL's length exceeds the capacity limit for this server.

My fear is that I have to find another method of transmitting the data or is a solution possible?

Code of XHR function:

function makeXHR(recordData) { if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest();

} else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

var rowData = "?q=" + recordData;

xmlhttp.open("POST", "insertRowData.php"+rowData, true); xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-Length",rowData.length); xmlhttp.setRequestHeader("Connection", "close");

xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { alert("Records were saved successfully!"); } }

xmlhttp.send(null);

}

+1  A: 

You should POST rowData in the request body via the send method. So, instead of posting to "insertRowData.php" + rowData, POST to "insertRowData.php" and pass the data in rowData to send.

I suspect that your rowData is a query string with the question mark. If that is the case, then the message body is simply rowData without the prepended question mark.

EDIT: Something like this should work:

var body = "q=" + encodeURIComponent(recordData);
xmlhttp.open("POST", "insertRowData.php", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = // ...
xmlhttp.send(body);
Daniel Trebbien
hi. i tried your code but now i dont get the data in my php script:PHP:$q = $_GET["q"]; echo $q;
@usurper: You need to use the `$_POST` superglobal array: `$q = $_POST['q']; echo htmlspecialchars($q);`
Daniel Trebbien
hmmm. this is what i got after using $q = $_POST['q'];: Undefined variable: q
yes. it worked now. thx.