Ajax sending _POST without maximum character

Asked

Viewed 57 times

2

In this ajax the post sends more than 1000 characters:

$.ajax({
            url: 'inserir.php',
            type: 'POST',
            data: { inseason: document.getElementById('comment').value },
            success: function(result) {
                alert('the request was successfully sent to the server');
            }
        });

But in this other one it has a maximum of 1000 characters and I can’t figure out why.

var http = new XMLHttpRequest();

        var parametros = "inseason=" + document.getElementById('comment').value;

        http.open("POST", "inserir.php", true);

        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        http.onreadystatechange = function() {
            if(http.readyState == 4 && http.status == 200) 
            {

                //console.log(http.responseText);
                $('#logs').text(http.responseText);

            }
        }
        http.send(parametros);
  • How did you find that the first sends more than 1000 characters and the second does not?

  • I have a textarea to put the result of the script , and in the second the post only sends 1000 characters

  • And what is the code of inserir.php?

  • Colloquium console.log(http.responseText.length); after $('#logs').text(http.responseText); and see what it shows on the console

  • now I was testing how many Cars passed with console.log(http.responseText.length); and found that when I pass a & in the code it confuses as more parameters and then only gives me the characters to the &

  • Puts escape(), thus: escape(document.getElementById('comment').value)

  • This will escape special characters such as &.

  • That’s right, thank you

  • Since I gave a hint and you found the main error, it would be nice if you posted an answer telling how the problem was solved and then mark as right, to give the question as finalized. Abs!

  • I’ll do that but I can only accept my answer after two days.

Show 5 more comments

1 answer

1


The mistake I had was that it would pass & in the post and ajax confused it as another parameter and the parameter I wanted to receive the text only showed me the characters up to the &.

Then I realized the mistake and the Dvd told me how to fix it:

escape(document.getElementById('comment').value)

Just change this in the parameters.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.