zoukankan      html  css  js  c++  java
  • jQuery—自定义HTTP请求

    Ajax设置自定义请求头的两种方法

    $.ajax({
        url: 'http://www.baidu.com',
        type: 'get',
        data: JSON.stringify({"name":"love python!"}),
        // 方法一:设置headers请求头参数
        headers: {"Content-Type": "application/x-www-form-urlencoded", "Accept": "text/plain"},
        success: function (data) {
            console.log(data)
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest.status);
            console.log(XMLHttpRequest.readyState);
        },
        complete: function(XMLHttpRequest, status) { } // 请求完成后最终执行参数
    });
    $.ajax({
        url: 'http://www.baidu.com',
        type: 'get',
        data: JSON.stringify({"name":"love python!"}),
        ContentType: "application/x-www-form-urlencoded"
        // 方法二:设置headers请求头参数
        beforeSend: function(request) {
            request.setRequestHeader("Accept", "text/plain");
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        },
        success: function (data) {
            console.log(data)
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            console.log(XMLHttpRequest.status);
            console.log(XMLHttpRequest.readyState);
            console.log(textStatus);
        },
        complete: function(XMLHttpRequest, status) { } // 请求完成后最终执行参数
    });
    

      

      

  • 相关阅读:
    apns libcurl
    apns libcurl
    epoll
    epoll
    Linux服务器压测
    Linux服务器压测
    libevent
    libevent
    shell脚本
    shell脚本
  • 原文地址:https://www.cnblogs.com/liuhaidon/p/11690775.html
Copyright © 2011-2022 走看看