Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Forked from cwhittl/fetch_plugin.js
Created May 14, 2021 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allysonsouza/70e3d700e9e446a6b51919ec8b1019c8 to your computer and use it in GitHub Desktop.
Save allysonsouza/70e3d700e9e446a6b51919ec8b1019c8 to your computer and use it in GitHub Desktop.
Using Fetch with Wordpress Plugins Ajax
fetch(ajax_url, {
method: 'POST',
credentials: 'same-origin',
headers: new Headers({'Content-Type': 'application/x-www-form-urlencoded'}),
body: 'action=zget_profile_user'
})
.then((resp) => resp.json())
.then(function(data) {
if(data.status == "success"){
_this.setState({loaded:true,user:data.user});
}
})
.catch(function(error) {
console.log(JSON.stringify(error));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment