我可以在HTML创建的div中显示ajax请求的结果,但是当PHP生成div时我不能这样做。任何人都可以解决一些问题吗?
$('#result'+id).html(result);
$show_results .='<div id="result'.$id.'">
//I want to show my result here..
</div>';
echo $show_results;
这只是代码的一部分..我已经通过ajax将值与它的id一起发送到数据库。
答案 0 :(得分:0)
尝试在$ .ajax请求中添加带有'html'的dataType参数作为值。例如:
.ajax({
type : 'POST',
dataType : 'html'
............. rest of your code
Jquery通常会尝试从检查MIME类型的请求中猜测返回内容的类型。
答案 1 :(得分:0)
这个PHP代码对我有用:
<?php
$id = 1;
$show_results .='<div id="result'.$id.'">
//I want to show my result here..
</div>';
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
</head>
<script>
var id = 1;
$(document).ready(function(){
$('#result'+id).html("42");
});
</script>
<body>
<? echo $show_results; ?>
</body>
</html>