zoukankan      html  css  js  c++  java
  • Ajax : $. get()和$.post() $.getScript $.getJSON

    <body>
        <input type="button" value="Ajax" />
        <div id="box"></div>
    </body>

    test.html

    <span class="name">党兴明</span>
    <span class="age">24</span>

    test.php

    <?php
        
    //    if($_POST['age'] == 24){
    //        echo 'php:党兴明24';
    //    }else{
    //        echo '木有';
    //    }    
        
        if($_GET['age'] == 24){
            echo 'php:党兴明24';
        }else{
            echo '木有';
        }
        
    ?>

    test.xml

    <?xml version="1.0"?>
    <root>
        <url>www.ycku.com</url>
    </root>

    test.josn

    [
        {
            "url" : "www.ycku.com"
        }
    ]

    $. get():

        //1 三种传值
        $('input').click(function(){
            $.get('test.php?age=24',function(response,status,xhr){
                $('#box').html(response);
            });
        });    
        //2 
        $('input').click(function(){
            $.get('test.php','age=24',function(response,status,xhr){
                $('#box').html(response);
            });
        });    
        //3
        $('input').click(function(){
            $.get('test.php',{
                age:24
            },function(response,status,xhr){
                $('#box').html(response);
            });
        });

    $.post()

        //1 两种传值
        $('input').click(function(){
            $.post('test.php','age=24',function(response,status,xhr){
                $('#box').html(response);
            });
        });    
        //2
        $('input').click(function(){
            $.post('test.php',{
                age:24
            },function(response,status,xhr){
                $('#box').html(response);
            });
        });

    读取.xml和.josn文件:

        $('input').click(function(){
            $.post('test.xml',function(response,status,xhr){
                $('#box').html($(response).find('root').find('url').text());
            });
        });
    
        $('input').click(function(){
            $.post('test.json',function(response,status,xhr){
                $('#box').html(response[0].url);
            });
        });

     $.getScript()

        $('input').click(function(){
            $.getScript('js/test.js');
        });

    $.getJSON()

        $('input').click(function(){
            $.getJSON('test.json',function(response,status,xhr){
                $('#box').html(response[0].url);
            });
        });
  • 相关阅读:
    从面向对象到SOA
    我对国内软件开发类书籍出版与写作的体会与努力
    MSDN for 2010的那些麻烦事
    金旭亮新作《.NET 4.0面向对象编程漫谈》之序“穿越梦想、起锚远航”
    Silverlight应用程序的本地通讯
    C#中Dictionary的用法
    泛型
    动态规划算法
    C# Timer
    面向对象程序设计寒假作业1
  • 原文地址:https://www.cnblogs.com/by-dxm/p/6391720.html
Copyright © 2011-2022 走看看