Good day, I am using Asp.Net Mvc 4 in combination with KnockoutJs for a website.
I have created a section to manage users and then added a busy indicator so that the user doesn't think nothing is happening as it takes a few seconds to save.
I've since learned that the browser will freeze the ui while posting data in a synchronized fashion, meaning that the gif that I am trying to display on my modal form does not display until the post is successful.
I then changed the async property to true ("async: true") which sure enough showed the progress loader....however now I am struggling with notifying whether the process was successful or not because when using "async: true" then the
javascript immediately jumps into the "error: " part without waiting for the server to finish saving.
Here is my javascript file that does the posting:
How do I trap whether the post was successful and wait for it? (I will look at alternatives if suggested)
Thanks
I have created a section to manage users and then added a busy indicator so that the user doesn't think nothing is happening as it takes a few seconds to save.
I've since learned that the browser will freeze the ui while posting data in a synchronized fashion, meaning that the gif that I am trying to display on my modal form does not display until the post is successful.
I then changed the async property to true ("async: true") which sure enough showed the progress loader....however now I am struggling with notifying whether the process was successful or not because when using "async: true" then the
javascript immediately jumps into the "error: " part without waiting for the server to finish saving.
Here is my javascript file that does the posting:
Code:
var urlPath = window.location.pathname;
function UserViewModel() {
$("#divProcessing").show(); //show the loader from here
var self = this;
self.username = ko.observable("");
self.password = ko.observable("");
self.emailaddress = ko.observable("");
self.saveUser = function () {
if (self.username() != "") {
$.ajax({
url: '/Home/CreateUser',
type: 'post',
async: false,
data: ko.toJSON(
{
UserName: self.username(),
Password: self.password(),
Email: self.emailaddress()
}
),
contentType: 'application/json',
success: function(data) {
alert(data);
},
error: function (data) {
alert(data);
}
});
}
}
}
var parent = document.getElementById('userpanel');
ko.applyBindings(UserViewModel,parent);
How do I trap whether the post was successful and wait for it? (I will look at alternatives if suggested)
Thanks