Created
July 5, 2017 14:18
-
-
Save claudioweb/d2134ba666c811b8842c929b12f05b2c to your computer and use it in GitHub Desktop.
Requisição WP AJAX - Jquery & javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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