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 关于#python#的问题:使用ATL02数据解算光子脚点的坐标(操作系统-windows)
  • ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据
  • ¥15 在matlab中Application Compiler后的软件无法打开
  • ¥15 想问一下STM32创建工程模板时遇到得问题
  • ¥15 Fiddler抓包443
  • ¥20 Qt Quick Android 项目报错及显示问题
  • ¥15 而且都没有 OpenCVConfig.cmake文件我是不是需要安装opencv,如何解决?
  • ¥15 oracleBIEE analytics
  • ¥15 H.264选择性加密例程
  • ¥50 windows的SFTP服务器如何能批量同步用户信息?