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);
    }
    });
     
     
  • 相关阅读:
    串口通信理论知识
    串口通信基础
    串口中断程序步骤及代码
    Django之CRM项目Day6-公私户转换问题解决 班主任功能
    Django之CRM项目Day5-跳转页面 跟进记录 报名记录
    Django之CRM项目Day4-编辑客户 公私户 模糊查询
    Django之CRM项目Day3-客户展示及分页
    Django的ModelForm
    Django相关面试题
    Django基础自测
  • 原文地址:https://www.cnblogs.com/justSmile2/p/9720333.html
Copyright © 2011-2022 走看看