ajax成功返回<?php <?php <?php <?php作为第一行

I am sending HTML code to ajax, and appending this code to the bottom of a list. Its for ajax paginating.

The code returned starts with

<?php<?php<?php<?php

and ends with

[1] 

what I am send is an array of html formatted activity items. This is an example of what I am getting back in ajax.

<?php<?php<?php<?php
<div class="activity">
<div class="activity-top"></div>
<div class="activity-body"></div>
</div>[1]

the item I am sending IS in an array.

the function returning code to looks like

function run_loop() {
    $each_item = array();
        if( has_activities( array('current_page' => $_POST['this_page'], 'user_id' => $_POST['user_id'] ) ) ) {

        while ( activity() ) : the_activity();

        $each_item[] =  include( dirname(dirname(__FILE__)).'/activity/activity-entry.php' );

        endwhile;
    }
    exit(json_encode($each_item));

}

Additionally, I tried working with the html code despite it being broken, and the parent div (container for activity) returned is not displayed. I am using .append().

It looks to me that you have two potential problems:

  1. You are rendering your activity-entry.php file as plain text.
  2. You are the Ajax method is returning a PHP array that is being written as its string representation by append.

A better way to handle this would be to return only the data you need, preferably in a format easily parsed by JavaScript (JSON), and then to render that data to HTML using jQuery, i.e. $('#pager').append('' + data +''