Skip to content

Instantly share code, notes, and snippets.

@cwhittl
Created April 13, 2017 14:42
Show Gist options
  • Save cwhittl/015827973d23ce657bfe09c735c9fa98 to your computer and use it in GitHub Desktop.
Save cwhittl/015827973d23ce657bfe09c735c9fa98 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));
});
@mattmintun
Copy link

This is killer! Thank you. I was able to modify this to download a PDF file from the server.

@cuchakma
Copy link

cuchakma commented May 7, 2021

Is there any demo or code for GET REQUEST in ajax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment