dongzaizai2015 2014-04-03 11:30
浏览 20
已采纳

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().

  • 写回答

1条回答 默认 最新

  • dongtangu8615 2014-04-03 11:46
    关注

    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 +''

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向