I have this view, as below, which is bound the viewModel/module shown below (loaded up via requirejs as per the KendoUI Mobile Music Store). When I load the page, the authenticate is being called (i.e., it's making that ajax network call as well).
<
div
data-role
=
"view"
id
=
"login-view"
data-layout
=
"blank"
data-model
=
"app.views.login.viewModel"
>
<
h1
style
=
"text-align: center;"
>Title</
h1
>
<
form
id
=
"login"
>
<
input
data-bind
=
"value: username"
id
=
"username"
type
=
"text"
placeholder
=
"Username"
/><
br
/>
<
input
data-bind
=
"value: password"
id
=
"password"
type
=
"password"
placeholder
=
"Password"
/><
br
/>
<
input
type
=
"submit"
value
=
"Login"
data-bind
=
"click: authenticate"
/>
</
form
>
</
div
>
define([
"jQuery"
,
"kendo"
,
"modernizr"
,
"app/environment"
],
function
($, kendo, modernizr, environment) {
var
authenticate =
function
(username, password) {
return
$.ajax({
url: environment.apiConnection +
'/canlogin?userid='
+ username +
'&password='
+ password,
type:
'get'
,
dataType:
'jsonp'
});
}
authenticate().done(
function
(data) {
alert(data);
}).fail(
function
() {
alert(
'fail'
);
})
return
{
viewModel: kendo.observable({
username:
null
,
password:
null
,
authenticate:
function
() {
var
username =
this
.get(
'username'
),
password =
this
.get(
'password'
);
authenticate(username, password);
if
(!Modernizr.localstorage) {
alert(
'There was an error accessing LocalStorage on this device.'
);
return
;
}
localStorage[
"username"
] = username;
localStorage[
"password"
] = password;
}
})
}
});