使用ajax从mysql获取详细信息

时间:2020-03-13 06:25:55

标签: php jquery ajax

请使用ajax / jQuery帮助我获取数组的所有对象。

我正在使用以下代码,但它不起作用

$(window).on("load", GetAllProperties);

function GetAllProperties() {
  $.ajax({
    url: 'userdetailfetch.php', //the script to call to get data                
    dataType: 'json', //data format      
    success: function(data) //on recieve of reply
    {
      $('#ph').html(data[0]);
      $('#email').html(data[1]);
      $('#name').html(data[2]);
      $('#fname').html(data[3]);
      $('#date').html(data[4]);
      $('#course').html(data[5]);
      $('#branch').html(data[6]);
      $('#sem').html(data[7]);
      $('#roll').html(data[8]);
    }
  });
}

fetchuserdetail.php

<?php
$cnx = mysqli_connect("localhost", "root", "", "loginerp");
$result = mysqli_query($cnx, "SELECT * FROM user_info WHERE id='" . $_SESSION['sessuser'] . "'");
$data = array();
while($row = mysqli_fetch_array($result)) {
    $data[] =$row;
}

echo json_encode($data);
?>

我想在页面加载时显示所有详细信息。

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

fetchuserdetail.php文件中的启动会话 session_start();

更正页面名称 网址:“ fetchuserdetail.php”,