Php verification request page source

Source: Internet
Author: User
Php verification request page Source: if ($ _ server [#39; http_x_requested_with #39;] #39; xmlhttprequest #... php verification request page Source:

if( $_server['http_x_requested_with'] == 'xmlhttprequest' ) {     echo 'ajax'; } else {     echo 'normal'; }

When jquery implements ajax internally, it has already added the identifier, which is shown in the jquery source code:

xhr.setrequestheader("x-requested-with", "xmlhttprequest");

Therefore, in php, you can use http_x_requested_with to determine whether another implementation is required. The following describes the principle: when sending an ajax request, we can use the xmlhttprequest object, create a custom header. if you are using the native ajax method, that is, the ajax method 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 custom header information before sending an ajax request.

$.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 retrieving data in php:

If (isset ($ _ server ['http _ request_type ']) & $ _ server ['http _ request_type'] = "ajax ") {// ajax submit} else {// non-ajax submit}


Link to this article:

Add to favorites ^ please keep the tutorial address.

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.