I have this Ajax request with jquery:
$(document).ready(function () {
var pageName;
$('li a').on('click', function (){
pageName = $(this).attr('data-url');
$.ajax({
type: 'GET',
url: 'http://mywebsite.com/' + pageName + '/?json=1',
contentType: 'application/json',
dataType: 'jsonp',
success: function(data) {
var page = data.content;
$('.mypage').html(page);
}
})
});
});
And i want change to XMLHttpRequest, so i did this:
function showPage () {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
document.getElementById('.mypage').innerHTML = httpRequest.responseText;
}
};
var attr = document.getElementByTagName(this);
var pageName = attr.getAttribute('data-url');
var url = 'http://mywebsite.com/' + pageName + '/?json=1',
httpRequest.open('GET', url);
httpRequest.send();
}
It's not working at all, anyone knows what i did wrong?