Hello! Please help. There is the following in scripts.js:

$.ajax({ type: "POST", url: "Makers_details.php", data:{ username: $("#username").val(), }, success: function (data) { $("#but3").html(data); } }); 

in the php file, the actual request in the database and the formation of the response in html. Here is the code:

 <?php $link = mysql_connect('localhost', 'root', '') or die('Не удалось соединиться: ' . mysql_error()); mysql_select_db('stepbystep') or die('Не удалось выбрать базу данных'); // Выполняем SQL-запрос $query = "SELECT * FROM firm where Name like '%".$_REQUEST['username']."%'"; $result = mysql_query($query) or die('Запрос не удался: ' . mysql_error()); // Выводим результаты в html echo "<table id='mytable'>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; $lat=$row['lat']; $lng=$row['lng']; $rows[] = $line; } echo "</table>\n"; return $result; ?> 

Actually everything works - in # but3 the result of the query is displayed from the database. But I just can't figure out how to continue working in ajax (right after the $ ("# but3") line. Html (data);) with the result of the query ... That is, I shoved the result into # but3, but I want to continue in the loop work with the result of the query ... Ie the result is roughly a table, so I need to run through this table and get data from each cell and say the same write them again in # but4 for example

  • You need to apply any cycle to data , for example, each api.jquery.com/jquery.each - Aleksey Shimansky
  • Almost fit ... But I don’t understand how to access rows and cells ... - Alexander
  • And it seems to me that after all he does not run in rows and columns, but for each symbol of the result ... (((( - Alexander
  • Show me an example answer - mix
  • jQuery.each (data, function (i, val) {alert (i, val); - Alexander

2 answers 2

 ... success: function (data) { $("#but3").html(data); var table = $('#mytable'); table.each(function(idx, tr) { console.log(tr); // Доступ к строкам $(tr).each(function(idx, td) { console.log(td); // Доступ к ячейкам }); }); } 

    Greetings.

    Here is an example of work

     ... success: function (data) { $("#but3").html(data); var table = $(data); // создает объект jQuery // дальше можно использовать привычные методы table.find('td'); // например найти все ячейки } ...