PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / admin / utils / ajaxRequest.js

ajaxRequest.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/admin/utils/ajaxRequest.js

45 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from "@wordpress/api-fetch";
2
3 /**
4 * Send Ajax Request To The Server
5 *
6 * @param {object} data
7 * @param {string} url
8 * @param {string} method
9 *
10 */
11 export function ajaxRequest(data, url, method, parse) {
12 return apiFetch({
13 url:url,
14 body:data,
15 method:method,
16 parse:parse,
17 });
18 }
19
20 /**
21 * Construct Data Using FormData(Applicable for only grid view admin panel, Do not use this function on other projects)
22 *
23 * @param {object} object
24 *
25 */
26 export function constructFormData(object) {
27 let formData = new FormData();
28
29 for( const key in object ) {
30 if( Array.isArray( object[key] ) ) {
31 for( let value of object[key] ) {
32 if( value?.hasOwnProperty('id') ) {
33 formData.append(`${key}[]`, value?.id);
34 } else {
35 formData.append(`${key}[]`, value);
36 }
37 }
38 } else {
39 formData.append(`${key}`, object[key]);
40 }
41 }
42
43 return formData;
44 }
45