AJAX--实现--JQuery实现方式--ajax(),get&post

    科技2024-08-11  27

    黑马程序员

    AJAX–实现–JQuery实现方式–ajax()

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="js/jquery-3.3.1.min.js"></script> </head> <body> <script> function btn_ajax() { $.ajax({ url: "AjaxServlet", type: "Post", data: {"name": "ajax", "age": 22}, success: function (data) { $("#myDiv").innerHTML = data alert(data) } }) } </script> <input type="button" value="发送异步请求" onclick="btn_ajax()"> <span id="myDiv"></span> <input> </body> </html>

    AJAX–实现–JQuery实现方式–get&post

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>AJAX--实现--JQuery实现方式--get</title> <script src="js/jquery-3.3.1.min.js"></script> </head> <body> <script> function btn_ajax() { $.get("AjaxServlet", {name: "get"}, function (data) { $("#myDiv").innerHTML = data alert(data) }, "text") } </script> <input type="button" value="发送异步请求" onclick="btn_ajax()"> <span id="myDiv"></span> <input> </body> </html> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>AJAX--实现--JQuery实现方式--post</title> <script src="js/jquery-3.3.1.min.js"></script> </head> <body> <script> function btn_ajax() { $.post("AjaxServlet", {name: "post"}, function (data) { $("#myDiv").innerHTML = data alert(data) }, "text") } </script> <input type="button" value="发送异步请求" onclick="btn_ajax()"> <span id="myDiv"></span> <input> </body> </html>
    Processed: 0.009, SQL: 8