# betterdocs/4.9.5/react-src/admin/utils/quickbuilderFetchFix.js

BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ &amp; Chatbot, version 4.9.5. 42 lines.

- Page: https://pluginprobe.com/plugins/betterdocs/4.9.5/code/react-src/admin/utils/quickbuilderFetchFix.js
- Raw: https://pluginprobe.com/plugins/betterdocs/4.9.5/raw/react-src/admin/utils/quickbuilderFetchFix.js
- Modified: 2026-10-12T10:07:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/betterdocs/4.9.5/code/react-src/admin/utils/quickbuilderFetchFix.js#L10-L20`.

```javascript
import apiFetch from "@wordpress/api-fetch";

/**
 * Give QuickBuilder's ajax requests an HTTP method.
 *
 * QuickBuilder's `hitAAJX()` calls `apiFetch({ path, data })` and never passes a
 * method — not even the one the field config declares. `data` makes apiFetch
 * attach a request body, and with no method the browser defaults to GET, so
 * `fetch()` rejects before anything leaves the page:
 *
 *     TypeError: Request with GET/HEAD method cannot have body.
 *
 * apiFetch turns that rejection into `{ code: "fetch_error", message: "Could not
 * get a valid response from the server." }` — which reads like a server or
 * network fault while the request was never actually sent. Every QuickBuilder
 * ajax button hits this: the AI Chatbot "Save", report test, import/export.
 *
 * This cannot regress a working request. It only fills in a method where the
 * call throws today, 100% of the time, so there is no success path to break.
 *
 * Scoped to our own namespace ON PURPOSE. Some select fields point `ajax.api` at
 * core routes (`/wp/v2/docs`, `/wp/v2/knowledge_base`) with data and an intended
 * `method: "GET"`; POSTing those would CREATE a post or a term instead of
 * reading a list. Those stay exactly as they are — the real repair for them is
 * teaching `hitAAJX()` to forward `ajax.method` upstream in QuickBuilder.
 */
const registerQuickBuilderFetchFix = () => {
    apiFetch.use( ( options, next ) => {
        const path = options?.path || "";
        const isOurs =
            path.startsWith( "/betterdocs/" ) || path.startsWith( "betterdocs/" );

        if ( isOurs && options?.data && ! options?.method ) {
            return next( { ...options, method: "POST" } );
        }

        return next( options );
    } );
};

export default registerQuickBuilderFetchFix;

```
