I'm Getting the Error "Updating failed. The response is not a valid JSON response"

This is a dreaded error that sometimes shows up after trying to update or publish a WordPress post or page.

When this error pops up, it’s a bit of a challenge to understand what’s going on since the error is so cryptic and doesn’t provide any concrete cause of the error.

Here are some tried and tested solutions that you can easily do to fix the error, and I’ll also let you know why they happen:

Head over to Settings > Permalinks, then click on Save Changes. Afterwards, check whether the saving error still occurs.

Cause / Reason:

WordPress uses URL rewriting for a number of things. Some to make URLs more reader or SEO friendly, or sometimes for internal needs such as custom post type URLs.

There’s a chance that when URL rewriting is adjusted in your site, the changes don’t get reflect right away. By saving your permalink changes, it forces the URL rewriting rules to be updated.

Solution #2: Turn off Performance Metrics

Turn off debugging or performance display metrics such as “Peak Memory Usage” or the number of “SQL Queries”

Cause / Reason

Some debugging or performance plugins occasionally prints out performance metrics on pages. These metrics can be found if you open up the source of your webpages.

Sometimes, these metrics gets placed also in some areas that may cause some normal WordPress functions to result in an error – such as when saving posts.

Solution #3: Don't Serve Mixed Content

If you’re using SSL (your site URL shows “https” and not “http”), make sure your site serves all HTTPS content.

Head over to Settings > General, and make sure your WordPress Address (URL) and Site Address (URL) both start with “https://”

If you’re using CloudFlare, make sure you’re setting for Encryption Mode is set to “Full (Strict)” mode.

Also make sure that you’re forcing all content to be served using HTTPS (this can be fixed either in your CDN settings, web hosting settings, or using an SSL plugin like Really Simple SSL

Cause / Reason

When you’re site is using SSL (when the URL shows “https”) and if your site is serving “mixed content” or both https and http URLs, and depending on your site set up, browsers could show a warning or won’t be able to load some URLs.

When this happens, some essential WordPress URLs may become inaccessible and might also affect the saving process.

Solution #4: Fix your .htaccess File

Make sure that your .htaccess rules are correctly set up.

Hostinger has a great article on how the .htaccess file should normally look like.

Cause / Reason

This is similar to the cause of the previous solution. What happens is that since your .htaccess file isn’t correctly set up, then some essential WordPress URLs may become inaccessible.

Solution #5: Adjust your Security Plugin

Check whether an installed security plugin is preventing certain actions or ajax calls from continuing.

Cause / Reason

Security plugins that provide firewall protection like WordFence can prevent some actions from being performed on your website, especially if you have them active on your website for some time. For these plugins, you may need to put them in "learning mode" again, or whitelist the action you're performing.

Solution #5: Ask your Web Hosting Provider

Ask the support team of your Web Hosting provider.

Cause / Reason

There's a chance your host has some security measure or firewall that's preventing your content from being saved.

For example, GoDaddy's Managed WordPress hosting prevents SVGs from being being saved in page contents, so you may have to contact technical support whether they can do something about this.

If None of the Solutions Above Work

If none of those work, then you’ll have to check what the WordPress save call is actually returning. To do this, you’ll have to view the actual call response in your browser’s developer tools. For Chrome:

  1. Right anywhere on the page, then select “Inspect” or “Inspect Element” to bring up the browser’s developer tools.

  2. Navigate to the “Network” tab of the developer tools

  3. Click on “XHR” in order to view only ajax calls

You should end up with something that looks like this:

Once you’re there, save your page, then check last of the newly added entries in the network tab.

Check the “Headers” tab of the new entry and you should see “/wp-json/…” in the “Request URL” to indicate that it’s a rest API call.

Check the “Response” tab, the contents of that may give a clue on what’s happening.