title: Trying to send a long string to a script via AJAX
body: <p>I am very newbie with javascript, and the last three hours I have been trying to deal with a problem sending data via AJAX. </p>
  
  <p>I am trying to send a string to a php file with a function. What this function does is to send a GET request to a php file which has a query and output an HTML; the function get the HTML and place it in "html_user_club".</p>
  
  <pre><code>    function userClubVotes(str_1,str_2,str_3) {
          if (str_1 == "") {
              document.getElementById("html_user_club").innerHTML = "";
              return;
          } else {
              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 (this.readyState == 4 &amp;&amp; this.status == 200) {
                      document.getElementById("html_user_club").innerHTML = this.responseText;
                  }
              };
              xmlhttp.open("GET",'ajax/ajax-user-club-votes.php?user_id='+str_1+'&amp;user_to_visit='+str_2+'&amp;following_votes='+str_3,true);
              xmlhttp.send();
          }
      }
  </code></pre>
  
  <p>It works, but only if the url is not very long. With this url it doesn't work:</p>
  
  <p>ajax/ajax-user-club-votes.php?user_id=13&amp;user_to_visit=134&amp;following_votes=1323.1323.134.23425.25245.42.24524.233.2344.232.1323.134.23425.25245.42.24524.233.2344.232.1323.134.23425.25245.42.24524.233.2344.232.1323.134.23425.25245.42.24524.233.2344.232.1323.134.23425.25245.42.24524.233.2344.232.23425.25245.42.24524.233.2344.232.1323.134.23425.25245.42.24524.233.2344.232.1323.134.23425.25245.42.24524.233.2344.232.1323.134.23425.25245.42.24524.233.2344.232.</p>
  
  <p>So, is there a way to send long url via AJAX?</p>
  
  <p>EDIT:</p>
  
  <p>Ok, so I have to send the string via POST instead of GET. I tried changing this:</p>
  
  <pre><code>xmlhttp.open("GET",'ajax/ajax-user-club-votes.php?user_id='+str_1+'&amp;user_to_visit='+str_2+'&amp;following_votes='+str_3,true);
  xmlhttp.send();
  </code></pre>
  
  <p>For this: </p>
  
  <pre><code>var string = '?user_id='+str_1+'&amp;user_to_visit='+str_2+'&amp;following_votes='+str_3;
  var body = "string=" + encodeURIComponent(string);
  xmlhttp.open("POST", "ajax/ajax-user-club-votes.php", true);
  xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-Length", body.length);
  xmlhttp.setRequestHeader("Connection", "close");
  xmlhttp.send(body);
  </code></pre>
  
  <p>But still without result. Any clue?</p>
  
  <p>EDIT_2</p>
  
  <p>Another try, first two variables via GET and the last via POST:</p>
  
  <pre><code>xmlhttp.open("GET",'ajax/ajax-user-club-votes.php?user_id='+str_1+'&amp;user_to_visit='+str_2,true);
  xmlhttp.send();
  var body = "string=" + encodeURIComponent(str_3);
  xhr.open("POST", "ajax/ajax-user-club-votes.php", true);
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xhr.setRequestHeader("Content-Length", body.length);
  xhr.setRequestHeader("Connection", "close");
  xhr.send(body);
  </code></pre>
  
  <p>Not success, but looks promising. Any idea? (I am trying to do something like in <a href="https://stackoverflow.com/questions/16159932/sending-a-long-string-through-ajax-doesnt-work">Sending a long string through ajax doesn&#39;t work</a></p>