Get the App
SLTechnology News&Howtos  ›  Development  › 

How to determine whether there is an attribute in the request header to determine whether it is an ajax request

Shulou Source: shulou.com Published: 2022-06-03 07:49:39 10月03日 Update

This article shows you how to judge whether the request header contains an attribute to determine whether it is an ajax request, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

The code is as follows:

Function cl ()

{

Var xmlhttp

If (window.XMLHttpRequest)

{

Xmlhttp=new XMLHttpRequest ()

}

Else

{

Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP")

}

Xmlhttp.open ("POST", "ajax2.html", true)

Xmlhttp.setRequestHeader ("Content-Type", "application/x- www-form-urlencoded")

/ / jquery YUI sends a HTTP request header message with HTTP_X_REQUESTED_WITH by default, so you can determine whether the ajax request is made by determining whether the attribute is contained in the request header.

Xmlhttp.setRequestHeader ('HTTP_X_REQUESTED_WITH',' HTTP_X_REQUESTED_WITH')

Xmlhttp.send ()

Xmlhttp.onreadystatechange=function ()

{

If (xmlhttp.readyState==4 & & xmlhttp.status==200)

{

Alert (xmlhttp.responseText)

}

}

}

Tags: Attributes content skills knowledge conciseness brevity code can be passed that is articles more news articles industry information channels channels lights reserves Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker MariaDB MySQL macOS