jQuery AJAX: How to pass large HTML tags as parameters?

Posted by marknt15 on Stack Overflow See other posts from Stack Overflow or by marknt15
Published on 2010-05-14T06:51:29Z Indexed on 2010/05/14 6:54 UTC
Read the original article Hit count: 249

Filed under:
|

Hello,

How can I pass a large HTML tag data to my PHP using jQuery AJAX? When I'm receiving the result it is wrong.

Thanks in advance.

Cheers, Mark

jQuery AJAX code:

$('#saveButton').click(function() {
        // do AJAX and store tree structure to a PHP array (to be saved later in database)
        var treeInnerHTML = $("#demo_1").html();
        alert(treeInnerHTML);
        var ajax_url = 'ajax_process.php';
        var params = 'tree_contents=' + treeInnerHTML;
        $.ajax({
            type: 'POST',
            url: ajax_url,
            data: params,
            success: function(data) {
                $("#show_tree").html(data);

            },
            error: function(req, status, error) { }
        });
});

treeInnerHTML actual value:

<ul class="ltr">
   <li id="phtml_1" class="open"><a href="#"><ins>&nbsp;</ins>Root node 1</a>
    <ul>
     <li class="leaf" id="phtml_2"><a href="#"><ins>&nbsp;</ins>Child node 1</a></li>
     <li class="last leaf" id="phtml_3"><a href="#"><ins>&nbsp;</ins>Child node 2</a></li>
    </ul>
   </li>
   <li id="phtml_5" class="file last leaf"><a href="#"><ins>&nbsp;</ins>Root node 2</a></li>
        </ul>

Returned result from my show_tree div:

<ul class="\&quot;ltr\&quot;">
   <li id="\&quot;phtml_1\&quot;" class="\&quot;open\&quot;"><a href="%5C%22#%5C%22"><ins></ins></a></li></ul>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX