Php verification request page source

Source: Internet
Author: User
Tags php tutorial

Php Tutorial verification request page source
If ($ _ server ['http _ x_requested_with '] = 'xmlhttprequest '){
Echo 'Ajax ';
} Else {
Echo 'normal ';
}

When jquery implements ajax internally, the ID has been added.
In jquery source code:
Xhr. setrequestheader ("x-requested-with", "xmlhttprequest ");

Therefore, you can use http_x_requested_with in php to determine whether to implement it separately :)


See the principles below

<Strong> when sending an ajax request, we can use the xmlhttprequest object to create

Defined header information </strong>
If you are using a native ajax method, that is, ajax that is not packaged using jquery or other js frameworks

The code is as follows:

Xmlhttprequest. setrequestheader ("request_type", "ajax ");
With jquery's $. ajax () method, you can easily create a custom

Header information.

$. Ajax ({
Type: "get ",
Url: base_url +

'Php _ check_ajax_request/get_user_list.html ',
Beforesend: function (xmlhttprequest ){
Xmlhttprequest. setrequestheader ("request_type", "ajax ");
},
Success: function (data ){
$ ("# User_list" ).html (data );
$ Tip. hide ();
$ Button. attr ('disabled ', true );
        }
});


When getting it in php

If (isset ($ _ server ['http _ request_type ']) & $ _ server ['http _ request_type']

= "Ajax") {// ajax submit
} Else {// non-ajax commit
}

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.