Title: JavaScript Syntax Error in admin.ajaxWatcher.js
Last modified: November 9, 2017

---

# JavaScript Syntax Error in admin.ajaxWatcher.js

 *  Resolved [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/javascript-syntax-error-in-admin-ajaxwatcher-js/)
 * Wordfence produces a Syntax error exception after an AJAX request returns a 404
   error.
 * **Steps to reproduce**
 * 1. Install Wordfence and use default setup.
    2. Create a tiny plugin with the
   following AJAX callback:
 *     ```
       function davilera_get_post() {
         // Let's assume we looked for the specified post, but we couldn't find it.
         header( 'HTTP/1.1 404 Not Found' );
         wp_send_json( "Post $post_id not found." );
       }
       add_action( 'wp_ajax_davilera_get_post', 'davilera_get_post' );
       ```
   
 * 3. Go to your browser, open the developer tools, and execute the following JavaScript
   snippet:
 *     ```
       jQuery.ajax({
         url: ajaxurl,
         data: {
           action: 'davilera_get_post',
           postID: 999999
         }
       });
       ```
   
 * **Expected results**
 * The AJAX request fails (404 error), nothing weird happens.
 * **Actual results**
 * The AJAX request fails as expected, but this results in an uncaught JS `Syntax
   error`:
 * `Uncaught Error: Syntax error, unrecognized expression: "Post 999999 not found."`
 * **Discussion**
 * Looking at the stack trace, the problem occurs in Wordfence’s script `admin.ajaxWatcher.
   js` line 17:
 * `var responseDOM = $(jqXHR.responseText);`
 * Why do you assume `responseText` will be a jQuery selector/node? In this example,
   the AJAX response is a simple string, but it could be anything else.
 * Thanks for addressing this issue!
    -  This topic was modified 8 years, 7 months ago by [David Aguilera](https://wordpress.org/support/users/davilera/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [wfalaa](https://wordpress.org/support/users/wfalaa/)
 * (@wfalaa)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/javascript-syntax-error-in-admin-ajaxwatcher-js/#post-9670508)
 * Hi David,
    Thanks for the detailed report you provided here, I appreciate your
   time.
 * I have passed this one to our dev team (internal reference number: #FB6322), 
   as I’m not sure when the appropriate update to this file will take place, you
   can uncheck both “Front” and “AdminPanel” checkboxes in (Wordfence > Firewall
   > [Monitor Background Requests for False Positives](https://docs.wordfence.com/en/WAF#Whitelisted_URLs))
   to avoid this problem.
 * Thanks.
 *  Thread Starter [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/javascript-syntax-error-in-admin-ajaxwatcher-js/#post-9670798)
 * I appreciate your help! How can I check the progress on #FB6322? Is there a link
   I can access?
 *  [wfalaa](https://wordpress.org/support/users/wfalaa/)
 * (@wfalaa)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/javascript-syntax-error-in-admin-ajaxwatcher-js/#post-9671925)
 * I’m afraid this is for internal referencing only on our system and which is not
   publicly accessible.
 * Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘JavaScript Syntax Error in admin.ajaxWatcher.js’ is closed to new replies.

 * ![](https://ps.w.org/wordfence/assets/icon.svg?rev=2070865)
 * [Wordfence Security - Firewall, Malware Scan, and Login Security](https://wordpress.org/plugins/wordfence/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordfence/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordfence/)
 * [Active Topics](https://wordpress.org/support/plugin/wordfence/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordfence/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordfence/reviews/)

## Tags

 * [firewall](https://wordpress.org/support/topic-tag/firewall/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)

 * 3 replies
 * 2 participants
 * Last reply from: [wfalaa](https://wordpress.org/support/users/wfalaa/)
 * Last activity: [8 years, 7 months ago](https://wordpress.org/support/topic/javascript-syntax-error-in-admin-ajaxwatcher-js/#post-9671925)
 * Status: resolved