Reputation: 1
I save the data on my DB. After i would display the new updated items calling the function "loadInitPosts()" This is my code:
function post_save_ajax() {
$(this).submit();
loadInitPosts();
}
function loadInitPosts() {
$.ajax({
type: "POST",
url: "home/loadInitPosts",
success: function (data) {
$(".posts").empty();
data = $.parseJSON(data);
$(".posts").append(data);
}
});
}
The function loadInitPosts is correctly called, but display the old data. It seems that is called before submit execute his task.
Upvotes: 0
Views: 433
Reputation: 393
function post_save_ajax() {
$(this).submit( function(){
loadInitPosts();
event.preventDefault();
});
}
function loadInitPosts() {
$.ajax({
type: "POST",
url: "home/loadInitPosts",
success: function (data) {
$(".posts").empty();
data = $.parseJSON(data);
$(".posts").append(data);
}
});
}
Upvotes: 0
Reputation: 11042
Try this:
$(this).submit(function () {
loadInitPosts();
});
Upvotes: 1