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

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

报告相同问题?

悬赏问题

  • ¥20 如何解决访问网址被屏蔽的情况
  • ¥15 本地运行的vue2项目,使用内网穿透,前端界面一直转圈圈
  • ¥20 powerbuilder datawindow控件导出Excel数据,可不可以不自动覆盖原数据,而是在后面新插入入数据。
  • ¥100 无轴承永磁同步电机控制
  • ¥15 eps里添加本地倾斜模型
  • ¥15 telegram 问题
  • ¥15 nrf52810-c三个a 程序
  • ¥50 求一个半透明没有锯齿的圆角窗体的实现例子
  • ¥15 STM32cubeMX里的FreeRTOS无法释放内存
  • ¥15 CATIA有些零件打开直接单机确定终止