shoyebzz

JavaScript Fetch API for WordPress Admin-ajax (GET)

Sep 24th, 2023 (edited)
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.45 KB | Source Code | 0 0
  1. var requestOptions = {
  2.       method: "GET",
  3.       redirect: "follow",
  4.     };
  5.  
  6.    
  7.     fetch(
  8.       formAction + "?action=sumw_product_search&search=" + searchQuery,
  9.       requestOptions
  10.     )
  11.     .then((res) => {
  12.         return res.json(); // Parse the response as JSON
  13.     })
  14.     .then((products) => {
  15.         console.log(products);
  16.     })
  17.     .catch((error) => {
  18.         console.error("error", error); // Log the error if there is one
  19.     });
Advertisement
Add Comment
Please, Sign In to add comment