我正在尝试POST
从提交事件中获取数据。对 REST 服务本身的请求正在运行。REST 服务有两个参数user
和password
. 我打印出这两个参数,所以我知道我的视图模型包含数据。如何将参数添加到请求中,服务器端的值为空?
PS。Oracle Jet 基于 KnouckoutJS、JQuery 和其他一些 JS 库构建。
登录.js
function homeContentViewModel() {
var self = this;
self.user = ko.observable("Super");
self.password = ko.observable("Sectret");
self.userInput = ko.pureComputed(function () {
return this.user() + " " + this.password();
}, this);
self.submitBt = function (data, event) {
alert(self.user() +" - " +self.password());
$.ajax({
url: "http://localhost:8080/myservice/rest/application/loginUser",
data: {user: self.user(), password: self.password()},
type: 'POST',
dataType: 'json',
success: function (data, textStatus, jqXHR) {
var x = data;
}
});
return true;
}
}
登录.html
<label for="text-input">User:</label>
<input id="text-input" type="text"
data-bind="ojComponent: {component: 'ojInputText', value: user}"/>
<label for="text-input">Password:</label>
<input id="text-input" type="text"
data-bind="ojComponent: {component: 'ojInputText', value: password}"/>
<br/>
<input id="submit" type="submit" data-bind="click: submitBt,
ojComponent: {component: 'ojButton', label: 'Login'}"/>