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').locationoddly 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?
ng-init=mq.currentDepth, wheremqis defined in a parentng-repeatandcurrentDepthis the JSON key whose value is being used. But it seems that theng-inithas been working so far since the data from the server is being on a 10 second timer as well. I'm just trying to sync it on the client side automatically.ng-modelorng-bind?ng-modellets you bind data to form elements, but that's tangential to what you seem to be asking here. I think you might want to start here stackoverflow.com/questions/14994391/… and then work through some angular tutorials (preferably without jQuery at all; it's more of a hindrance than a help in angular.) Angular takes quite a bit of getting used to; it's not well suited to the just-dive-in-and-try-stuff approach.