javascript - Fetch multiple data from a php file using AJAX and insert them in different input fields -


i using ajax in order access data php file. have problem format of retrieved data database, please help.

so, ajax function splice. retrieves data find_account.php

function processreqchange() {      // if req shows "loaded"      if (req.readystate == 4) {          // if "ok"          if (req.status == 200) {              form_prof.prof_id.value = req.responsetext;     form_prof.prof_name.value = req.responsetext;     form_prof.prof_username.value = req.responsetext;     form_prof.prof_password.value = req.responsetext;          }          else {              alert("problem in retrieving xml data:\n" + req.statustext);          }      }  } 

find_account.php

<?php  include("connect.php"); session_start();  $account = $_get['account']; $query = "select * profs profs_name = '".$account."'"; $result = mysql_query($query); $num = mysql_num_rows($result);  if(empty($num)) { echo 'data not found'; } else {     $arr = mysql_fetch_array($result);     $id = $arr['profs_number']; $name = $arr['profs_name']; $username = $arr['profs_username']; $password = $arr['profs_password']; }  header("content-type: text/plain"); echo $id; echo $name; echo $username; echo $password; ?> 

and have 4 input boxes in html req.responsetext puts value

and everytime search name in input field example:

search: [ dorothy perkins ] 

the output goes [id,name,username,password]:

[20111dorothy perkinsdperkins@mail.com123456] [same 1st field] [same] [same]  

wherein want like...

[20111]  [dorothy pekins]  [dperkins@mail.com]  [123456] 

where [ ] input fields. please me arrange format, confused. new this.

you have write data in format php code (xml, json, or separate values comma), , parse javascript.

for example, in php:

echo $id . "," . $name . "," . $username . "," . $password; 

and in javascript:

values = req.responsetext.split(","); form_prof.prof_id.value = values[0] form_prof.prof_name.value = values[1]; form_prof.prof_username.value = values[2]; form_prof.prof_password.value = values[3]; 

of course may have more complicated if values may contain comma.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -