Ajax:回声阵列&填充文本框

时间:2015-05-12 20:07:54

标签: php jquery ajax

我的目标是填写几个"输入文本框"与一些ajax。现在,我设法以这种方式填充单个文本框:

document.getElementById("meow").value=xmlhttp.responseText;

这是我的php脚本,它返回mysql结果,通过" echoing"它:

$result = mysqli_query($link,"SELECT * FROM user WHERE auth = '".$q."'");
while($row = mysqli_fetch_array($result)) {echo $row['prenom'].$row['nom'];}

我的问题是:我可以从我的php脚本中回显整个数组(或某种特殊字符串),然后使用ajax解析它,这样我就可以用适当的数据填充文本框(我已经尝试了几种方法,像Json.parse,但它不起作用,或者我做错了)?谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

Problem solved. I managed like this : I put a separator between each data taken from the database, like so :

SELECT col1, col2 FROM table WHERE id=-1
UNION ALL
SELECT '', '' -- OR 0, 0 whatever is appropriate
;

And on the other side, I parse the data, and I put it in the right textbox, this way :

while($row = mysqli_fetch_array($result)) {echo $row['prenom'].";".$row['nom'];}