2

I am trying to post some data to a php file by using following code.

var exam = document.getElementById("information").getAttribute("examid");
            var user = document.getElementById("information").getAttribute("userid");
            var question = document.getElementById("information").getAttribute("questionid");

            var xmlhttp;
            xmlhttp=new XMLHttpRequest();
            xmlhttp.open("GET","savevalue.php?examid="+exam+"&userid="+user+"&questionid="+question+"&content="+ editor.getValue(),true);
            xmlhttp.send();
            xmlhttp.onreadystatechange=function()
            {
               if (xmlhttp.readyState==4 && xmlhttp.status==200)
              {

              }
            }

But the first problem is if the variable that I am posting contains too many characters, this method fails. Secondly if one of the variables that I am posting contains '&' char, it also fail. Should I replace & with something else?

halfer
  • 19,824
  • 17
  • 99
  • 186
Xlerone
  • 45
  • 1
  • 5
  • If the data in one of the paramaters? What does that mean? – Álvaro González Oct 07 '15 at 14:37
  • 4
    Possible duplicate of [Best practice: escape, or encodeURI / encodeURIComponent](http://stackoverflow.com/questions/75980/best-practice-escape-or-encodeuri-encodeuricomponent) – Álvaro González Oct 07 '15 at 14:38
  • I don't understand 1st problem... – n00dl3 Oct 07 '15 at 14:39
  • If variables in the example like question and user have too many characters like 6000 characters , it fails.I mean that if var user="123" (3 chracters) , there is no problem but if it has more like 6000, it fails – Xlerone Oct 07 '15 at 14:41
  • beacuse you are supposed to use post as get has limitation. – madi Oct 07 '15 at 15:02
  • to make ur life better i rather suggest you use jquery ajax unless you are not supposed to use jquery ajax – madi Oct 07 '15 at 15:03

1 Answers1

0

As mentioned in comments, use the POST method instead of GET, because POST allows much more data/characters across in one message.

Also for the ampersand (&), that is a special character that needs to be escaped, or you could use & notation

Kieran101
  • 565
  • 5
  • 18