skip to Main Content

Actually I have a params : id, token, action:”hosts”

Some example like Getting host= “https://example.com/mnt/api/v1/store/1/actions

  1. How to pass the required parameters to the endpoint. (or) How to call end point with required data ?

2

Answers


  1. Not entirely sure what you are after, if you are after how to call that using jquery ajax, then it will be something like this. I haven’t used jQuery for a while, but base on my memory this is what I used to write. Also you can find more information from https://api.jquery.com/jquery.ajax/

    $.ajax({
       url: "https://example.com/mnt/api/v1/store/1/actions",
       method: "post" // or you can use "get"
       dataType: "json",
       data: {
          id: 1,
          token: token,
          action: "hosts"
       },
       success: your_callback,
       error: your_callback
    });
    
    Login or Signup to reply.
  2. You can pass the parameters to a function, add the variables to the url and then reference the url in the ajax call instead of the url address e.g.

    ``
    function myFetchPostsByCategory(id) {
             var id = id;
    
              var new url = `/wordpress/wp-json/wp/v2/posts?categories=${id}`;
    ```
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search