使用jQuery和php include创建php



嗯,我已经创建了一个代码,在一个框中包含一个PHP页面,而不仅仅是正常的include ('');

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
    <script>
        $(function() {
            var count = 1;
            $('#append').click(function() {
                if (count < 2) {
                    $('#parent').append('<div id="first' + count + '">text</div>');
                    $('#first1').load('../image/index.php');
                    count++;
                }
            });
        });
    </script>
    <a id="append">Add DIV 1</a>
    <div id="parent">
    </div>
</body>
</html>

现在,我注意到我可以在html中"加载"一个页面,但所有的php和javascript代码都是"out"。如何将"真实"页面放到另一个

PHP代码没有返回,因为它是在服务器上执行的,然后才从它返回HTML。为了以纯文本形式检索它,您需要更改您试图检索的文件。

至于如何在另一个页面中加载一个页面,您可以使用iframes。

试试这个:

<script>
$(function(){
  var count = 1;
  $('#append').click(function(){
      if (count <2){
         $('#parent').append('<div id="first'+count+'">text</div>');
         $.get('http://test.com/image/index.php',function(data){
             $('#first1').html(data);
         });
         count++;
      }
  });
});
</script>

最新更新