Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This ajax has an action that can be used to run function and access the data values as $_POST['mydata'] in the callback function

 $.ajax({
      url: qrAjax.ajax_url,
      type: 'POST',
      context: this,
      data: {
        action: 'qrcode_post_create',
        nonce: qrAjax.nonce,
        mydata : datas,
      },
      success: function(response) {
        alert("Success");
        $(".qrresponse").append(response);
      },
    });

Is there a way to do a similar thing with fetch()?

 fetch('https://mywebsite.online/wp-json/wp/v2/qrcode', {
      method: 'POST',
      credentials: 'same-origin',
      headers: new Headers({
        'Content-Type': 'application/json;charset=UTF-8',
        'X-WP-Nonce' : qrAjax.nonce
      }),
      body: JSON.stringify(OurPostData),
    }).then(response => {
      console.log(response);
      return response.json();
    }).then(data => console.log(data));
question from:https://stackoverflow.com/questions/65644434/fetch-post-request-actions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
281 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...