Difference between AJAX request and a regular browser request

后端 未结 6 1766
予麋鹿
予麋鹿 2020-12-23 11:09

Is there a difference between an AJAX request and a direct browser request (in terms of how a web page is called and loaded)?

In other words, I mean: is a direct ser

6条回答
  •  别那么骄傲
    2020-12-23 11:54

    Some popular client-side libraries like jQuery include the X-Requested-With header in their requests and set it to XMLHttpRequest to mark them as AJAX.

    This seems to have been considered standard enough a few years ago (probably due to the huge popularity of jQuery and its presence in almost every website) that many server-side frameworks even have helpers that take care of checking for this header in the received request for you:

    ASP.NET MVC 5:

    HttpRequestBase.IsAjaxRequest()
    

    Django:

    HttpRequest.is_ajax()
    

    Flask:

    flask.Request.is_xhr
    

    However, it seems that with the end of jQuery's reign in the front end world and the standardization of the fetch API and the rise of other modern client-side libraries that don't add any header for this purpose by default, the pattern has fallen into obsolescence also in the backend; with ASP.NET MVC not including the helper in newer versions and Flask marking it as deprecated.

提交回复
热议问题