For example, to report an error to the user, use the following method:
You can use set_error_handler to set your own error handling function. trigger_error is used in the error reporting area, and an error information page is displayed in the custom error handling function.
However
If the page that calls trigger_error is triggered by an Ajax request, a lot of HTML code is returned by ajax to display the error. While average
Ajax calls all agree on their own error information format, so the backend PHP code either uses two different reporting methods: one for Ajax call requests, refresh a common page
Use, or use a unified error report format. When reporting, determine whether this is an Ajax call request or a normal page refresh request.
In PHP code, the method for detecting Ajax call requests is as follows:
If (isset ($ _ server ['HTTP _ x_requested_with ']) &
Strtolower ($ _ server ['HTTP _ x_requested_with ']) = 'xmlhttprequest '){
// This is an Ajax request
}
This method is from Google search and is said to be only applicable to Ajax requests sent by jquery.