PDA

View Full Version : Ext.Ajax.request params



ChillsNL
3 May 2011, 5:17 AM
Hello people,
My app is slowly taking more of his shape and yesterday i'd made an dynamic form. Now i'm trying to make some things more dynamically. The first step of everything is an log in form.

When the button has been pressed on the log-in form, the handler calls out a function with an Ext.Ajax.request.

Unfortunally, it doesn't work because i can't send params with it. I've tested it with an endpoint who needs no params, and that works. Only when there are params involved, the Request ends up as an 400 bad request.

Someone willing to look for me?

The only problem is that my webservice accept params in the form of: '{"GWUserName":"[var]","GWPassword":"[var]"}'. Noticed that [var] needs to be replaced by the filled in username and password.

Code:

function Login()
{
LoginName = FWM.LoginForm.getValues().name;
LoginPass = FWM.LoginForm.getValues().password;

sParams = '{"GWUserName":"'+LoginName+'","GWPassword":"'+LoginPass+'"}';
Ext.Ajax.request
({
url: 'GWService.svc/GWEndPoint/CheckLogin',
method: 'POST',
params: sParams,
success: function(response)
{
console.log(response.responseText);
},
failure: function(response)
{
console.log(response.responseText);
}

});
}

or


function Login()
{
LoginName = FWM.LoginForm.getValues().name;
LoginPass = FWM.LoginForm.getValues().password;

Ext.Ajax.request
({
url: 'GWService.svc/GWEndPoint/CheckLogin',
method: 'POST',
params:
{
GWUserName:LoginName,
GWPassword:LoginPass
},
success: function(response)
{
console.log(response.responseText);
},
failure: function(response)
{
console.log(response.responseText);
}

}) ;
console.log(Login_Check);
}

Both give me the 400 bad request.

Anyone?

ChillsNL
3 May 2011, 11:11 PM
Anyone a clue?

realjax
4 May 2011, 2:41 AM
Take a look through firebug (or some other debug console) to see what is actually being posted (what does the full request look like) and report back with that here.

ChillsNL
4 May 2011, 3:06 AM
Already got that fixed a few minutes ago.


var LoginData = new Object();
LoginData.GWUserName = FWM.LoginForm.getValues().name;
LoginData.GWPassword = FWM.LoginForm.getValues().password;

Ext.Ajax.request
({
url: 'GWService.svc/GWEndPoint/CheckLogin',
method: 'POST',
success: function(response, opts)
{
GetLoginResult = eval('('+response.responseText+')');
LoginStatus = GetLoginResult.CheckLoginResult;

if(LoginStatus == "true")
{
FWM.LoginForm.hide();
}
else if(LoginStatus == "false")
{
alert("Can not log in into FreightWare Mobile. Wrong username / password");
}
},
failure: function(response, opts)
{

},
scope: this,
jsonData: LoginData
});

yuriy.ivlyev
4 May 2011, 3:12 AM
Hi,
You can build json object for params:

sParams = {GWUserName: LoginName, GWPassword: LoginPass};