gpt4 book ai didi

javascript - 从 Oracle Jet 中的提交事件提交数据

转载 作者:行者123 更新时间:2023-11-30 00:11:49 27 4
gpt4 key购买 nike

我正在尝试从提交事件中POST 数据。对 REST 服务本身的请求正在运行。 REST 服务有两个参数userpassword。我打印出这两个参数,所以我知道我的 View 模型包含数据。如何将参数添加到请求,服务器端的值为空?

附言。 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'}"/>

最佳答案

你提到...

REST service has two parameters name and password.

但是在您的 $.ajax 调用中,您将数据设置为...

{user: self.user(), password: self.password()}

我觉得应该是...

{name: self.user(), password: self.password()}

我不能确定,但​​这种不匹配可能是它不起作用的原因。

另外,使用浏览器的网络跟踪来查看您的请求是什么样的。如果您在请求中没有看到您的值,那么它会解释为什么它们没有出现在服务器上。

关于javascript - 从 Oracle Jet 中的提交事件提交数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36159936/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com