How to debug error in WordPress Ajax Request

When WordPress develop create develop something ajax in WordPress, it’s very difficult to check the ajax PHP error. sometimes it takes more time to handle just one simple error. when the error was too simple. I have faced the same situation, after that, I did some research on it, I found a solution for it. let’s dig into it.

first, we have to turn on WP_DEBUG mode.

Go to Your Domain Folder, find wp-config.php, and open it Now find this line:


define( 'WP_DEBUG', false );

now replace false with true


define( 'WP_DEBUG', true );

Now we have turned on error reporting, Go to wp-includes folder, find load.php file. open it and find this line below code:

if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
ini_set( 'display_errors', 0 );
}

and replace it with this line:

 

 if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() || wp_is_json_request() ) {
ini_set( 'display_errors', 1 );
}

that’s it. now go to the page, where you are requesting ajax. before sending an ajax request, open inspect element and click on Network

 

now if send an ajax request and there will request details you can see, click on it, you will get details of it on the right side. Like this:


Now you can debug your ajax request in WordPress. if you still face issues with debugging WordPress Ajax, Please let me know in the comment section below. we can discuss to solve it.

One Comment

Add a Comment