1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| <html> <head> <meta type="text/html" charset="utf8" /> <title>异步请求数据库cms user表中的数据</title> <script src="jquery-3.2.1.js"> </script> </head> <body> <input type="text" value="15" name="username" /> <button id="main">提交</button> <div id="user"> </div> <script>
$("#main").click(function(){ var username=$("input[name='username']").val(); $.ajax({ type : 'get', data:{ 'username':username} , dataType:'json', url:'user.php', console.log(xhr) console.log('发送前') } , */ success:function (response,status, xhr) { $("#user").html("<table border=1 width=800> </table>"); for(var i in response){ var str="<tr> <td>"+response[i].id+"</td> <td>"+response[i].username+"</td> </tr>"; $("table").append(str); } } , error:function(){ alert("wronngh"); }
}); } ) </script> </body> </html>
|