zoukankan      html  css  js  c++  java
  • ajax

    一、定义

    AJAX = 异步 JavaScript 和 XML(Asynchronous JavaScript and XML;简短地说,在不重载整个网页的情况下,AJAX 通过后台加载数据,并在网页上进行显示

    二、用法

    $("#id").load()

    load(url,data,function(response,status,xhr))
    $("button").click(function(){
      $("div").load('demo_ajax_load.txt');
    });

    $.get();
    $.get("http://datainfo.duapp.com/shopdata/getclass.php",function(data){
                console.log(data)        })
    $.get("http://datainfo.duapp.com/shopdata/getuser.php?userID=f66",function(data){
                console.log(data)
            },"JSONP");
    $.get("http://datainfo.duapp.com/shopdata/getCar.php",{userID:"f66"},function(data){
                console.log(data)
            },"JSONP")

    $.post(URL,data,callback);
    $.post("http://datainfo.duapp.com/shopdata/getuser.php?userID=f66",function(data){
                console.log(data)        },"JSONP");        $.post("http://datainfo.duapp.com/shopdata/getCar.php",{userID:"f66"},function(data){            console.log(data)        },"JSONP")

    $.ajax();
    $.ajax({
          type:"get",
          url:"",
          function(data){
                console.log(data)      
            }
      });

    $.getJSON();
    $.getJSON("http://datainfo.duapp.com/shopdata/getCar.php?userID=f66&callback=?",function(data){
               console.log(data)        })
    
        
    $.getJSON("pro.json",function(data){ 
    console.log(data) sortPrice(data); data.sort(function(a,b){ return a.price - b.price; }) console.log(data) })

    $.getScript();
             $.getScript("test.js",function(){
                    setTimeout(function(){
                        alert(2)
                    },2000)
                })
    用法区分
    ajax 使用举例


    三、扩展
    1. 请求出错时 识别状态 打印状态码
    $.ajax({
    url: "theme1.txt",
    type: "POST",
    data: {

    },
    dataType: "text",
    success: function (xml, textStatus, xhr) {
    console.log(xml);
    console.log(textStatus);
    console.log(xhr);
    },
    // error:function(xml, textStatus, xhr){
    // console.log('error');
    // console.log(xml);
    // console.log(textStatus);
    // console.log(xhr);
    // },
    complete: function (xhr, textStatus) {
    console.log('complete');
    console.log(xhr.status);
    console.log(textStatus);
    }
    });
     
     
  • 相关阅读:
    mysql 函数在源码中的定义
    mydumper工作原理 :myownstars专家
    drop table big_table 调试
    debugfs恢复文件
    Linux内核里的DebugFS
    在Linux环境中使用Ext3文件系统
    strace
    通过blktrace, debugfs分析磁盘IO
    block_dump观察Linux IO写入的具体文件(mysqld)
    Centos下的IO监控与分析
  • 原文地址:https://www.cnblogs.com/justSmile2/p/9720333.html
Copyright © 2011-2022 走看看