[英]Fetching large data from MySQL database in an AJAX request
I am building a PHP application which makes use of Ajax as well. 我正在构建一个使用Ajax的PHP应用程序。
The Ajax code i am using is 我正在使用的Ajax代码是
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 处理此问题的PHP函数是
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". 我定义了一个ID为“ updateform”的div。 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.
例如:在VARCHAR(200)字段中,如果我存储Stack Overflow ,则仅显示Stack 。
Is my method for fetching the data wrong? 我的数据提取方法是否错误?
First var_dump($row);
第一个
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
由于您缺少html输出中
name
和value
的引号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.