The function jQuery.getJson() is a alias for an AJAX HTTP GET call, that is, you are only using the method ajax() from the library, so you are only using one asynchronous call and receiving a JSON as a response, correct?
To do the same without importing the entire library you can use XMLHttpRequest which is what the method jQuery.ajax() (and its derivative jQuery.getJSON()) uses, since the same is only a wrapper.
While with jQuery you would
$.ajax('service/user/1234', {
method: 'POST',
contentType: 'application/json',
processData: false,
data: JSON.stringify({
name: 'João de Barros',
age: 34
})
})
.then(function success(userInfo) {
// userInfo será um objeto contendo propriedades como nome, idade,
// endereço, etc.
});
With Xmlhttprequest you would do so
var xhr = new XMLHttpRequest();
xhr.open('POST', 'service/user/1234');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if (xhr.status === 200) {
var userInfo = JSON.parse(xhr.responseText);
// userInfo será o mesmo objeto contendo propriedades como nome,
// idade, endereço, etc.
}
};
xhr.send(JSON.stringify({
name: 'João de Barros',
age: 34
}));
Ref.:
You can search for solutions in javascript ("pure") equivalent to its functions that is used in
jQuery– Lauro Moraes
If the request method is
GETYou may be helped with this question: http://answall.com/questions/188577/como-obten-o-conte%C3%Bado-de-arquivo-javascript-na-forma-de-string/188834#188834– Lauro Moraes