This simple problem has flustered me this morning. I've searched for a solution to this problem on SO, but have only found solutions which involve loading data into HTML, or a refresh for the whole page. I'm trying to use jQuery's $.ajax
function to refresh certain HTML elements. These elements have the same class. I don't want to load new data into these elements with jQuery; that is being handled by Angular. If I manually refresh the page (without jQuery at all), the new data is there. However, I want to refresh this part of the page automatically. I don't want to refresh the whole page.
So far I have this:
setInterval('reloadPage()', 10000);
function reloadPage() {
$.ajax({
async: true,
dataType: 'json',
type: 'GET',
url: 'http://localhost:8080/app/rest/json',
error: function(err) {
console.log(err.statusText);
},
success: function() {
$('.mq').location.reload(true);
console.log($('.mq').location);
}
});
}
$('.mq').location.reload(true);
is undefined. I know that I'm using reload
incorrectly in two ways:
- You can't use it with
('.mq').location
oddly enough... I feel like that should be a feature. reload(true)
forces to reload the page from the server, but I'm not sure the page is being served by the server on each reload, it's only being updated... I don't know, I'm fuzzy on this.
I've also tried $('.mq').load(url)
, but that just inserts the first JSON element from the URL for all of the HTML elements being updated. This isn't what I want since the proper values are being controlled by Angular directives in the HTML (yes, I know I should probably use a controller for this instead).
So, how to refresh multiple HTML elements at once with jQuery's $.ajax
function?