I am trying to POST
data from submit event. The request to the REST service itself is working. The REST service has two parameters user
and password
.
I print-out the two parameters so I know my view model contains the data.
How can I add the parameters to the request, the values are empty on the server-side?
PS. Oracle Jet is build on KnouckoutJS, JQuery and some other JS libs.
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'}"/>
You mention that...
REST service has two parameters
name
andpassword
.
But in your $.ajax
call, you set data to...
{user: self.user(), password: self.password()}
I think that should be...
{name: self.user(), password: self.password()}
I can't be sure, but that mismatch might account for why it isn't working.
Also, use the browser's Network tracking to see what your request looks like. If you don't see your values in the request, then it would explain why they aren't showing up on the server.