为了账号安全,请及时绑定邮箱和手机立即绑定

使用Jquery Ajax从Mysql中检索数据

使用Jquery Ajax从Mysql中检索数据

忽然笑 2019-07-30 15:20:26
使用Jquery Ajax从Mysql中检索数据list.php:一个简单的ajax代码,我只想显示Mysql表的记录:<html><head>     <script src="jquery-1.9.1.min.js">     </script>     <script>     $(document).ready(function() {         var response = '';         $.ajax({             type: "GET",             url: "Records.php",             async: false,             success: function(text) {                 response = text;             }         });         alert(response);     });     </script></head><body>     <div id="div1">         <h2>Let jQuery AJAX Change This Text</h2>     </div>     <button>Get Records</button></body></html>Records.php是从Mysql获取记录的文件。在数据库中只有两个字段:“名称”,“地址”。<?php    //database name = "simple_ajax"     //table name = "users"     $con = mysql_connect("localhost","root","");     $dbs = mysql_select_db("simple_ajax",$con);     $result= mysql_query("select * from users");     $array = mysql_fetch_row($result);?><tr>     <td>Name: </td>     <td>Address: </td></tr><?php    while ($row = mysql_fetch_array($result))     {         echo "<tr>";         echo "<td>$row[1]</td>";         echo "<td>$row[2]</td>";         echo "</tr>";     }   ?>此代码无效。
查看完整描述

3 回答

?
aluckdog

TA贡献1847条经验 获得超7个赞

您不能返回ajax返回值。存储全局变量存储返回后的返回值。
或者像这样更改你的代码。

AjaxGet = function (url) {
    var result = $.ajax({
        type: "POST",
        url: url,
       param: '{}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
       async: false,
        success: function (data) {
            // nothing needed here
      }
    }) .responseText ;
    return  result;}


查看完整回答
反对 回复 2019-07-30
  • 3 回答
  • 0 关注
  • 589 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信