Didn"t forge 2017-04-06 18:56 采纳率: 25%
浏览 20

Ajax请求什么?

So I have a stupid question about this:

$.ajax({
            type: "GET",
            url: `URL`,
            data: DO STUFF WITH WHAT I GOT FROM THE REQUEST???,
        });

In ajax, when I make a get request from a URL, with the data: parameter am I giving a response that is data or is data the data I received from the request?

  • 写回答

2条回答 默认 最新

  • derek5. 2017-04-06 19:16
    关注

    The main thing to understand here is that any AJAX call (any web request really) has two components: A request and a response. The actual $.ajax() function call is sending the request, and a callback function is provided to handle the response.

    To illustrate:

    $.ajax({
        type: "GET", // request type
        url: "http://www.example.com/someResource", // destination URL
        data: { name: "David", location: "Boston" } // data to send
    });
    

    This would make a GET request to the specified URL, sending it the specified data. The response in this case is ignored, since no callback is provided. But you can provide one:

    $.ajax({
        type: "GET",
        url: "http://www.example.com/someResource",
        data: { name: "David", location: "Boston" }
    }).done(function(response) {
        // handle the response
    });
    

    The function which contains "handle the response" will be called by the system when the AJAX response is received from the server. The response variable (or whatever you want to call that variable, the name doesn't matter) will contain whatever the server sent in return. Which could be anything, really.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统