Syrion
@Syrion

How can i send data from sql to jqueryUI dialog window?

I am new. I have a table in jQueryUI dialog window. How can I get data from SQL database to table cells? I failed with AJAX =\ How to correctly do it?

When open-event of modal dialog_window i try to get one row from sql db where id = var from another_element (var is passed successfully here, I checked).

$("#dialog_window").dialog({
    open: function() {
    var id = $("#another_element").data('id');
        $.ajax({
          type: 'POST',
          url: 'response.php',
          data: id,
          success: function(data) { 
          alert(data['F']); //try to show one of the elements of the array
          },
          error:  function(xhr, str){
                alert(xhr.responseCode);
          }
        });
},
.........
.........
});


response.php:

<?php
$name = 'name'; 
$password = 'password'; 
header("Content-Type: text/html;charset=utf-8");
mysql_connect("localhost", "$name", "$password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$str = "Select * from table WHERE id='".$_REQUEST['id']."'"; 
$result = mysql_query($str) or die(mysql_error());
$row=mysql_fetch_assoc($result); //I tried to use mysql_fetch_assoc and
//mysql_fetch_row

mysql_close();

echo($row);
?>
  • Вопрос задан
  • 297 просмотров
Решения вопроса 1
@lemme
Frontend
echo json_encode($row);

alert(JSON.parse(data['F']));

You have to send JSON encoded string, and then parse it.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы