亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用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 關注
  • 639 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號