The solution is a mixture of e.preventDefault()
and using a callback in the ajax call. Just using the callback didn't resolve the issue, but adding preventDefault
to the authenticate
function and fixing the callback issue did.
The final, working version, now looks something like this:
define(["jQuery", "kendo", "modernizr", "app/environment"], function ($, kendo, modernizr, environment) {
function authenticate(username, password, callback) {
$.ajax({
url: environment.apiConnection + '/canlogin?userid=' + username + '&password=' + password,
type: 'get',
dataType: 'jsonp',
success: callback,
error: function (x,t,r) {
console.log('error')
}
});
}
function login(canLogin, username, password) {
if (canLogin == false) {
alert('Incorrect username or password');
return;
}
alert('good');
}
return {
viewModel: kendo.observable({
username: null,
password: null,
authenticate: function (e) {
e.preventDefault();
var username = this.get('username'),
password = this.get('password');
authenticate(username, password, function (canLogin) {
login(canLogin, username, password);
});
}
})
}
});