zoukankan      html  css  js  c++  java
  • 夺命雷公狗jquery---55---Ajax的高级实现,模拟发送get请求

    jQuery.get(url,[data],[callback]) 或 $.get

    jQuery.post(url,[data],[callback]) 或 $.post

    参数说明:

    url请求的url页面

    [data]发送Ajax时传递的参数,要求格式为json对象,如果没有可以不写,直接写第三个参数即可

    [callback]Ajax状态码为4响应状态码为200所触发的回调函数

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="">
            <title></title>
            <script src="js/jquery.js"></script>
            <script>
                $(function(){
                    $('#btnok').bind('click',function(){
                        //发送ajax请求
                        $.get('ajax4.php',function(msg){
                            alert(msg);
                        });
                    });
                });
            </script>
        </head>
        <body>
            <input type="button" id="btnok" value="OK" />
        </body>
    </html>

    PHP代码如下:

    <?php
        echo "Ajax jQuery";

    在此运行以上代码,发现存在缓存行问题,可以通过以下方法进行决解

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="">
            <title></title>
            <script src="js/jquery.js"></script>
            <script>
                $(function(){
                    $('#btnok').bind('click',function(){
                        //发送ajax请求
                        var data = {
                            _:new Date().getTime()  //t通过这种方法可以解决缓存问题
                        };
                        $.get('ajax4.php',data,function(msg){
                            alert(msg);
                        });
                    });
                });
            </script>
        </head>
        <body>
            <input type="button" id="btnok" value="OK" />
        </body>
    </html>
  • 相关阅读:
    JSP 隐含对象
    Cookie 和 Session
    Servlet(Server Applet) 详解
    AbstractQueuedSynchronizer 详解
    ThreadLocal 详解
    线程的生命周期
    phpfor函数和foreach函数
    php的while函数
    php的switch函数
    php的if函数
  • 原文地址:https://www.cnblogs.com/leigood/p/4924232.html
Copyright © 2011-2022 走看看