dsbm49845 2014-05-25 17:56
浏览 37
已采纳

在AJAX请求中从MySQL数据库中获取大数据

I am building a PHP application which makes use of Ajax as well.

The Ajax code i am using is

    function getdetails(id){
var xhr;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}
else{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}

xhr.onreadystatechange = function(){
    if(xhr.readyState==4 && xhr.status==200){
        document.getElementById("updateform").innerHTML=xhr.responseText;
    }
}

xhr.open("GET","get_details?id="+id+"&table="+'<?php echo $table_name ?>',true);
xhr.send();
}

The PHP function that handles this is

public function get_details(){
        $id = $_GET['id'];
        $table = $_GET['table'];
        $query = $this->db->get_where($table,array('id'=>$id));
        if($query){
            $row = $query->row();
            echo form_open('members/update_detail');
            foreach ($row as $key => $value) {
                echo $key.'     <input type="text" name='.$key.' value='.$value.'><br>';
            }
            echo '</form>';
        }

        //echo $_GET['id'];
    }

I have defined a div with id "updateform". The code is working fine in the sense that it is fetching data. However, it is not fetching the entire data. For example : in a VARCHAR(200) field, if I store Stack Overflow , only Stack is getting displayed.

Is my method for fetching the data wrong?

  • 写回答

1条回答 默认 最新

  • doudang1890 2014-05-25 18:21
    关注

    First var_dump($row); and check it is as you expect.

    Then instead of

     echo $key.'     <input type="text" name='.$key.' value='.$value.'><br>';
    

    try

    echo $key.'<input type="text" name="'.$key.'" value="'.$value.'"><br>';
    

    As you're missing the quotes in the html output for name and value

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

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助