我无法取回我的数据,这里是我的代码。哪里有问题?谢谢。jquery ajax post成功返回数据
的index.php
<script type="text/javascript">
jQuery(document).ready(function(){
$(".click").click(function(){
var value = $(this).val();// post each click value to another page
$.ajax({
url: "post.php",
dataType: "html",
type: 'POST', //I want a type as POST
data: "name="+value,
success: function(data){
$("#result").data($data);
}
});
});
});
</script>
<div id="result"></div>
<a href="#" class="click">tim</a>
<a href="#" class="click">tom</a>
<a href="#" class="click">jimmy</a>
post.php中
<?php
$name=trim(addslashes(htmlspecialchars(rawurldecode($_POST["name"]))));
$data .='Your name is '.$name;
$data .='how do you do';
echo $data;// how to return all the html in post.php? or return $data part?
?>
这不是问题(@Tatu已经举报过但是分开来说:如果你没有正确编码你的数据,你会*在某些时候遇到麻烦。你需要在你的'value'变量上调用'encodeURIComponent':'data:“name =”+ encodeURIComponent(value)'当你为'data'参数传递一个字符串时,**你**正在为它负责被编码。 (或者,让jQuery处理它:'data:{name:value}'。) – 2011-05-15 09:01:43