zoukankan      html  css  js  c++  java
  • Jquery调用ajax参数说明

    代码中有详细注释,直接上代码。

    注释掉的选项,一般用不到,直接用最基本的部分就可以了。

                $.ajax({
                    // 请求的URL
                    url: '../Daily/Daily_Report',
    
                    //HTTP method:"POST", "GET", "PUT"
                    // 这样写也行 method: 'POST',
                    type: "POST",
    
                    // 发送到服务器的数据
                    data: {
                        "user":"abc"
                    },
    
                    // default: true
                    // 是否异步,默认是异步的
                    //async: true,
                    
                    // default: true
                    // 发送数据前,会将data属性指定的object转换成query string
                    // 指定成false后,object的数据在后台得不到
                    //processData: true,
    
                    // default: 'application/x-www-form-urlencoded; charset=UTF-8'
                    // values: application/x-www-form-urlencoded, multipart/form-data, or text/plain
                    // 发送给服务器的数据类型,UTF-8编码是固定的,改不了的。
                    // 设定为false,就是不设定contentType给服务器,可以省略
                    //contentType: false,
    
                    // 服务器返回的数据类型,不指定的话,jquery回根据服务器指定的MIME进行推断。
                    // 所以,如果服务器指定了MINE类型,可以省略
                    //dataType:"json",
    
                    // 发送前调用的函数
                    // 如果返回false,将取消ajax请求
                    //beforeSend: function (xhr, settings) {
                    //},
    
                    // 对返回数据的预处理
                    // 这里的data是原始的response的数据,比success函数的data要早,
                    // 如有需要,可以对返回的原始值进行处理,然后再返回data
                    //dataFilter:function(data, type){
                    //},
    
                    // 成功时调用的函数
                    // 这里的data已经是根据dataType,格式化好的数据,比如一个json对象。
                    success: function (data, textStatus, xhr) {
                        if (data !== null) {
                        }
                    },
    
                    // 异常时调用的函数
                    //  Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror".
                    // When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error."
                    error: function (xhr, textStatus, errorThrown) {
                    },
    
                    // ajax请求完成调用的函数,这个函数在success和error后调用,不论成功或失败都要做的操作放在这里
                    //textStatus:"success", "notmodified", "nocontent", "error", "timeout", "abort", or "parsererror"
                    complete: function(xhr, textStatus){
                    }
                });
  • 相关阅读:
    【设计】B端图表设计
    用 SpringBoot,亲自打造一个在线题库系统
    玩点创意编程,发现另一个世界
    Spring Security 基本介绍,初窥路径
    一个课程,11个项目!爬虫初体验,快来!
    黑三兵后现缓涨很危险 出现急涨有转机
    JavaScript对象之get/set方法
    ES6-ES11新特性
    js常见设计模式
    再谈promise
  • 原文地址:https://www.cnblogs.com/xiashengwang/p/8085140.html
Copyright © 2011-2022 走看看