AJAX sending html content in half

Asked

Viewed 53 times

0

I have a problem with the publishing system.

When I will make a new post and fill in all fields: Title, photo and post the code var myArea2 = document.getElementById('myArea2'); var post = myArea2.innerHTML; takes all the html element inside the div with id myArea2until then it really takes everything, but when I send by ajax to another php page where it $_POST it prints the contents of myArea2 for half.

It’s like the ajax I’ve been sending it in half, it doesn’t go through ALL OVER the content.

function enviarPost() {
            var url_s = "<?php print $url_s; ?>";

            var myArea2 = document.getElementById('myArea2');
            var post = myArea2.innerHTML;

            var now_date = document.getElementById('now_date');
            var data = now_date.innerHTML;

            var now_autor = document.getElementById('now_autor');
            var autor = now_autor.innerHTML;

            var title = $('#title_post').val();

            var result_i = document.getElementById('result_i');
            var img = result_i.innerHTML;

            if(post != '' || title != '' || img != '') {
                var dataString = 'title='+title+'&data='+data+'&autor='+autor+'&img='+img+'&post='+post+'&type=postagem';
                $.ajax({
                    type: "POST",
                    url:  url_s+"server/teste.php",
                    data: dataString,
                    cache: false,
                    success: function(tihidResponse){
                        $("#sample").html(tihidResponse);
                    }
                });
            } else {
                alert("Todas as informações tem de estar preenchida: Titulo, imagem e texto de postagem.");
            }
        }

What should be a complete publication:

inserir a descrição da imagem aqui

Returns only the beginning of the publication, as if it only took the first tag of the content HTML envoy.

inserir a descrição da imagem aqui

Does anyone have any solution??

I tried with type: "GET" by ajax, but it was wrong 414 (Request-URI Too Long).

1 answer

1


GET would not work, there are limits to the size of the sent string.

Try to change that:

var dataString = 'title='+title+'&data='+data+'&autor='+autor+'&img='+img+'&post='+post+'&type=postagem';

That’s why:

var dataString = { 
    title: title,
    data: data,
    autor: autor,
    img: img,
    post: post,
    type: postagem
};

Of course in your PHP you will have to adapt, but in principle will send everything.

  • Thanks for the help. I had already done it and it really worked.

Browser other questions tagged

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