0

我可以在 HTML 创建的 div 中显示 ajax 请求的结果,但当 div 由 PHP 生成时,我不能这样做。任何人都可以阐明一些光???

$('#result'+id).html(result);

$show_results .='<div id="result'.$id.'">
//I want to show my result here..
</div>';

echo $show_results;

这只是代码的一部分..我已经通过 ajax 将值连同它的 id 一起发送到数据库。

4

2 回答 2

0

尝试将“html”作为值的 dataType 参数添加到您的 $.ajax 请求中。例如:

.ajax({
    type : 'POST',
    dataType : 'html'
............. rest of your code

Jquery 通常会尝试从检查 MIME 类型的请求中猜测返回内容的类型。

于 2013-07-04T20:48:58.297 回答
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>
于 2013-07-04T21:35:49.267 回答