jQuery中Ajax的load方法详解

2020-05-23 06:19:58易采站长站整理

     *      如果没有参数传递,则采用GET方式进行传递;
     *      反之,则会自动转换为POST传递
     *
     * **/
</script>
</html>

load()方法—回调函数


<!DOCTYPE html>
<html>
<head lang=”en”>
    <meta charset=”UTF-8″>
    <script type=”text/javascript” src=”../../js/jquery-2.1.3.js”></script>
    <style>
        * { margin:0; padding:0;}
        body { font-size:12px;}
        .comment { margin-top:10px; padding:10px; border:1px solid #ccc;background:#DDD;}
        .comment h6 { font-weight:700; font-size:14px;}
        .para { margin-top:5px; text-indent:2em;background:#DDD;}
    </style>
    <title></title>
</head>
<body>
<input type=”button” id=”send” value=”Ajax获取” />
<div class=”comment”>已有评论</div>
<div id=”resText”></div>
</body>
<script type=”text/javascript”>
    $(function () {
        $(“#send”).click(function () {
            $(“#resText”).load(“test.html .para”, function (responseText, textStatus, XMLHttpRequest) {
                alert($(this).html());
                alert(responseText);//请求返回的内容
                alert(textStatus);//请求状态:success、error、notmodified、timeout
                alert(XMLHttpRequest);//XMLHttpRequest对象
            });
        });
    })
    /**
     *
     * load()方法的回调参数
     *
     * **/
</script>
</html>

END