【问题标题】:Submit data from a submit event in Oracle Jet从 Oracle Jet 中的提交事件提交数据
【发布时间】:2016-07-09 16:01:21
【问题描述】:

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

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


【解决方案1】:

你提到...

REST服务有两个参数namepassword

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

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

我觉得应该是……

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

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

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

【讨论】:

  • 谢谢,今天一切正常。参数的名称实际上是úser´and ´password´,改变了问题文本。
猜你喜欢
  • 2019-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-07
  • 1970-01-01
  • 1970-01-01
  • 2012-09-02
相关资源
最近更新 更多