【发布时间】:2016-07-09 16:01:21
【问题描述】:
我正在尝试 POST 来自提交事件的数据。对 REST 服务本身的请求正在运行。 REST 服务有两个参数user 和password。
我打印出这两个参数,所以我知道我的视图模型包含数据。
如何将参数添加到请求中,服务器端的值为空?
PS。 Oracle Jet 基于 KnouckoutJS、JQuery 和其他一些 JS 库构建。
login.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;
}
}
login.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'}"/>
【问题讨论】:
-
在 chrome 调试器网络选项卡中调试您的 ajax 请求,看看您是否收到 404、200 或其他错误消息。
标签: javascript jquery knockout.js oracle-jet