如何使用jQuery
AJAX将大型
HTML标记数据传递给我的
PHP?当我收到结果时,这是错误的.
@H_404_2@jQuery AJAX代码:
$('#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) { } }); });@H_404_2@treeInnerHTML实际值:
<ul class="ltr"> <li id="phtml_1" class="open"> <a href="#"><ins> </ins>Root node 1</a> <ul> <li class="leaf" id="phtml_2"> <a href="#"><ins> </ins>Child node 1</a> </li> <li class="last leaf" id="phtml_3"> <a href="#"><ins> </ins>Child node 2</a> </li> </ul> </li> <li id="phtml_5" class="file last leaf"> <a href="#"><ins> </ins>Root node 2</a> </li> </ul>@H_404_2@从我的show_tree div返回结果:
<ul class="\"ltr\""> <li id="\"phtml_1\"" class="\"open\""> <a href="%5C%22#%5C%22"><ins></ins></a> </li> </ul>
解决方法
查看是否将字符串中的参数更改为对象有助于:
var params = { tree_contents: treeInnerHTML };@H_404_2@见http://jsfiddle.net/7bF2Y/