Skip to main content
edited tags
Link
souslov
  • 44.7k
  • 11
  • 92
  • 113
edited tags
Link
souslov
  • 44.7k
  • 11
  • 92
  • 113
Post Closed as "Duplicate" by Darragh Enright, Patrick Evans, Greg, Maks3w, Anonymous
added 53 characters in body
Source Link
dlofrodloh
  • 1.7k
  • 3
  • 25
  • 48

I'm sending a string via xmlhttp in javascript using the following code:

    function SendPHP(str, callback) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                     
                             
                         callback(xmlhttp.responseText); //invoke the callback
        }
    }
        xmlhttp.open("GET", "testpost.php?q=" + encodeURIComponent(str), true);
    
    xmlhttp.send();

}

and some test php:

$q = $_GET['q'];
echo $q;

That worked fine until I started sending a larger string in which case I get the "HTTP/1.1 414 Request-URI Too Long" error.

After a bit of research I found out I need to use "POST" instead. So I changed it to:

xmlhttp.open("POST", "sendmail.php?q=" + str, true);

And:

$q = $_POST['q'];
echo $q;

But this does not echo anything when using POST. How can I fix it so it works like when I was using GET but so it can handle a large string of data?

edit I'm now trying it with:

function testNewPHP(str){

  str = "q=" 
 + str;
  alertxmlhttp = new XMLHttpRequest("in);
 funct: "  
str = "q=" + encodeURIComponent(str);
  
  alert (str);
   
xmlhttp.open("POST","testpost.php", true);
  xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState == 4){
       if(xmlhttp.status == 200){
                            alert (xmlhttp.responseText);
       }
      }
    };
  xmlhttp.setRequestHeader("Content-type", "text"application/csv; charset=utfx-8"www-form-urlencoded");
  xmlhttp.send(str);

}

I'm sending a string via xmlhttp in javascript using the following code:

    function SendPHP(str, callback) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                     
                             
                         callback(xmlhttp.responseText); //invoke the callback
        }
    }
        xmlhttp.open("GET", "testpost.php?q=" + encodeURIComponent(str), true);
    
    xmlhttp.send();

}

and some test php:

$q = $_GET['q'];
echo $q;

That worked fine until I started sending a larger string in which case I get the "HTTP/1.1 414 Request-URI Too Long" error.

After a bit of research I found out I need to use "POST" instead. So I changed it to:

xmlhttp.open("POST", "sendmail.php?q=" + str, true);

And:

$q = $_POST['q'];
echo $q;

But this does not echo anything when using POST. How can I fix it so it works like when I was using GET but so it can handle a large string of data?

edit I'm now trying it with:

function testNewPHP(str){

  str = "q=" + str;
  alert ("in funct: " + str);
    
  xmlhttp.open("POST","testpost.php", true);
  xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState == 4){
       if(xmlhttp.status == 200){
                    alert(xmlhttp.responseText);
       }
      }
    };
  xmlhttp.setRequestHeader("Content-type", "text/csv; charset=utf-8");
  xmlhttp.send(str);

}

I'm sending a string via xmlhttp in javascript using the following code:

    function SendPHP(str, callback) {
    if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else { // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                     
                             
                         callback(xmlhttp.responseText); //invoke the callback
        }
    }
        xmlhttp.open("GET", "testpost.php?q=" + encodeURIComponent(str), true);
    
    xmlhttp.send();

}

and some test php:

$q = $_GET['q'];
echo $q;

That worked fine until I started sending a larger string in which case I get the "HTTP/1.1 414 Request-URI Too Long" error.

After a bit of research I found out I need to use "POST" instead. So I changed it to:

xmlhttp.open("POST", "sendmail.php?q=" + str, true);

And:

$q = $_POST['q'];
echo $q;

But this does not echo anything when using POST. How can I fix it so it works like when I was using GET but so it can handle a large string of data?

edit I'm now trying it with:

function testNewPHP(str){

     
    xmlhttp = new XMLHttpRequest();
    
str = "q=" + encodeURIComponent(str);
 
  alert (str);
 
xmlhttp.open("POST","testpost.php", true);
xmlhttp.onreadystatechange=function(){
  if (xmlhttp.readyState == 4){
     if(xmlhttp.status == 200){
                            alert (xmlhttp.responseText);
     }
    }
  };
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(str);

}
deleted 79 characters in body
Source Link
dlofrodloh
  • 1.7k
  • 3
  • 25
  • 48
Loading
added 589 characters in body
Source Link
dlofrodloh
  • 1.7k
  • 3
  • 25
  • 48
Loading
Source Link
dlofrodloh
  • 1.7k
  • 3
  • 25
  • 48
Loading