Skip to content

Instantly share code, notes, and snippets.

@claudioweb
Created July 5, 2017 14:18
Show Gist options
  • Save claudioweb/d2134ba666c811b8842c929b12f05b2c to your computer and use it in GitHub Desktop.
Save claudioweb/d2134ba666c811b8842c929b12f05b2c to your computer and use it in GitHub Desktop.
Requisição WP AJAX - Jquery & javascript
var data = "action=posts";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "/wp-admin/admin-ajax.php");
xhr.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
var settings = {
"async": true,
"crossDomain": true,
"url": "/wp-admin/admin-ajax.php",
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"cache-control": "no-cache"
},
"data": {
"action": "posts",
"page" : 1
}
}
$.ajax(settings).done(function (resposta) {
console.log(resposta);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment