ajax 简单操作

 
<script>

         $(function () {

             //$("#send").click(function () {

             //    $.get("JQuery.ashx", { username: $("#username").val(), content: $("#content").val() }, function (msg) {

             //        $("#resText").html(msg);

             //    });

             //});

             $("#send").click(function () {

                 $.post("JQuery.ashx", { username: $("#username").val(), content: $("#content").val() }, function (msg) {

                     $("#resText").html(msg);

                 });

             });

         });

     </script>

<body>

    <form id="form1" action="#">

        <p>评论:</p>

        <p>姓名:<input type="text" name="username" id="username"  /></p>

        <p>内容:<textarea name="content" id="content" rows="2" cols="20"></textarea></p>

        <p><input type="button" name="name" value="提交 " id="send" /></p>

    </form>

    <div class="comment">

        已有评论

    </div>

    <div id="resText">

    </div>

</body>

第二种

<html><!DOCTYPE html>

<html>

<head>

<script>

    function loadXMLDoc() {

        var xmlhttp;

        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari

            xmlhttp = new XMLHttpRequest();

        }

        else {// code for IE6, IE5

            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

        }

        xmlhttp.onreadystatechange = function () {

            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

                document.getElementById("myDiv").innerHTML = xmlhttp.responseText;

            }

        }

        xmlhttp.open("GET", "WebForm2.aspx", true);

        xmlhttp.send();

    }

</script>

</head>

<body>



<div id="myDiv"><h2>使用 AJAX 修改该文本内容</h2></div>

<button type="button" onclick="loadXMLDoc()">修改内容</button>



</body>

</html>

			

w3cSchool.cc
转载自  
http://www.cnblogs.com/dyxd/p/4261364.html

 

你可能感兴趣的:(Ajax)