Based on John's response, I changed the GET request to a POST request. It works without changing the server configuration. So I went to see how to implement this. The following pages were helpful:
jQuery Example AJAX POST with PHP (Note the sanitation note) and
http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
Basically the difference is that the GET request has the URL and parameters on the same line and then sends null:
http.open("GET", url+"?"+params, true); http.send(null);
whereas a POST request sends the URL and parameters to separate commands:
http.open("POST", url, true); http.send(params);
Here is a working example:
ajaxPOST.html:
<html> <head> <script type="text/javascript"> function ajaxPOSTTest() { try { // Opera 8.0+, Firefox, Safari ajaxPOSTTestRequest = new XMLHttpRequest(); } catch (e) { // Internet Explorer Browsers try { ajaxPOSTTestRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajaxPOSTTestRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { // Something went wrong alert("Your browser broke!"); return false; } } } ajaxPOSTTestRequest.onreadystatechange = ajaxCalled_POSTTest; var url = "ajaxPOST.php"; var params = "lorem=ipsum&name=binny"; ajaxPOSTTestRequest.open("POST", url, true); ajaxPOSTTestRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); ajaxPOSTTestRequest.send(params); } //Create a function that will receive data sent from the server function ajaxCalled_POSTTest() { if (ajaxPOSTTestRequest.readyState == 4) { document.getElementById("output").innerHTML = ajaxPOSTTestRequest.responseText; } } </script> </head> <body> <button onclick="ajaxPOSTTest()">ajax POST Test</button> <div id="output"></div> </body> </html>
ajaxPOST.php:
<?php $lorem=$_POST['lorem']; print $lorem.'<br>'; ?>
I just sent over 12,000 characters without any problems.
atmelino Apr 30 '14 at 3:30 2014-04-30 03:30
source share