Php verification request page source

Source: Internet
Author: User

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
}

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.