PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / assets / js / public / Api.js

Api.js in WP Ultimate Post Grid 4.0.1, at assets/js/public/Api.js

53 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const endpoint = wpupg_public.api_endpoint;
2
3 export default {
4 loadItems( body ) {
5 let loadEndpoint = endpoint;
6
7 // WP Extended Search compatibility for text search filter.
8 if ( body.hasOwnProperty( 'args' ) && body.args.hasOwnProperty( 'wpes' ) && 0 < body.args.wpes ) {
9 loadEndpoint += `?wpessid=${ body.args.wpes }`;
10 }
11
12 let headers = {
13 'Accept': 'application/json',
14 'Content-Type': 'application/json',
15 // Don't cache API calls.
16 'Cache-Control': 'no-cache, no-store, must-revalidate',
17 'Pragma': 'no-cache',
18 'Expires': 0,
19 };
20
21 if ( 0 < parseInt( wpupg_public.user ) ) {
22 headers['X-WP-Nonce'] = wpupg_public.api_nonce;
23 }
24
25 const args = {
26 method: 'POST',
27 headers,
28 credentials: 'same-origin',
29 body: JSON.stringify( body ),
30 };
31
32 return fetch( loadEndpoint, args ).then( function ( response ) {
33 if ( response.ok ) {
34 return response.json();
35 } else {
36 // Log errors in console and try to get as much debug information as possible.
37 console.log(loadEndpoint, args);
38 console.log(response);
39
40 try {
41 response.text().then(text => {
42 console.log(text);
43 })
44 } catch(e) {
45 console.log(e);
46 }
47
48 return false;
49 }
50 } );
51 },
52 };
53