Hybrid View
-
27 Jul 2012 12:50 AM #1
How to append Url
How to append Url
Hi,
How to append url in proxy ? My scenario are like below:
I have two variable strUsername and strPassword they contains values strUsername ="Doe" and strPassword "xyz".
url is :-http://10.4.3.199/FineDocsMobileServices/Service1.svc/{0}", "GetGNLogEN?
Now I want to append strUsername and strPassword's values in url
like :
http://10.4.3.199/FineDocsMobileServices/Service1.svc/{0}", "GetGNLogEN?Username="Doe" &Pd=xyz;
my codes are:-
Ext.application({
launch: function () {
Ext.create('Ext.List', {
fullscreen: true,
items: [{
xtype: 'toolbar',
docked: 'top',
title:'List',
//store:'Contacts',
itemTpl: '{Username}' +
'{Password}'
}]
}
);
Ext.define('Contacts', {
extend: 'Ext.data.Model',
config: {
fields: [{
name: 'Username',
type: 'string'
}, {
name: 'Password',
type: 'string'
}]
}
});
var store = Ext.create('Ext.data.Store', {
model:'Contacts',
proxy: {
type: 'jsonp',
url : 'http://localhost:51047/SenchaTest/Default.aspx?',//This is the part where i want to apend url for username and password
callbackKey: 'callback',
reader:{
type:"json",
rootProperty:"contacts"
}
},
autoLoad:true
});
store.load();
}
});
-
27 Jul 2012 4:31 AM #2
-
27 Jul 2012 1:02 PM #3
If your store is setup something like this:
Notice the extraParams section. That is where the extra variable names are set. Also notice there should be no "?" on the url. That will be added.Code:Ext.define('App.store.Jobs', { extend: 'Ext.data.Store', requires: [ 'Ext.data.proxy.JsonP', ], config: { model: 'App.model.Job', autoLoad: false, proxy: { type: 'jsonp', url: 'http://www.someurl.com/jobs', startParam: '', pageParam: '', limitParam: '', extraParams: { userName: false, userPassword: false, } } } });
Then within your app, do something like this:
Then when you call your load method, it will send the information along with the request.Code:var jobsStore = Ext.getStore('Jobs'); // Apply the params to jobs store jobsStore.getProxy().setExtraParam('userName', 'someusername'); jobsStore.getProxy().setExtraParam('userPassword', 'somepassword');
-
30 Jul 2012 10:26 PM #4
Hi gcw07,
Thank you for your valuable solution.
But i have a small problem when i submit the button request data is not updated in first time if i again hit the button then it provides the correct result.
I think data is not updated in first time. please help me if i am missing ...
my store code is
Ext.define("NotesApp.store.Login", {
extend: "Ext.data.Store",
requires: [
'Ext.data.proxy.JsonP', "Ext.data.Model"
],
config: {
model: "NotesApp.model.Login",
proxy:{
type:"jsonp",
url:"http://10.4.3.199/SenchaTest/Default.aspx",
startParam: '',
pageParam: '',
limitParam: '',
extraParams: {
Un: false,
Pd: false
},
reader:{
type:"json",
rootProperty:"res"
}
},
autoLoad:true
}
});
and code of submit button event are:
var loginStore = Ext.getStore('Login');
// Apply the params to login store
loginStore.getProxy().setExtraParam('Un', txt);
loginStore.getProxy().setExtraParam('Pd', pwd);
loginStore.load();
Thanks & Regards
Vipin
-
30 Jul 2012 11:17 PM #5
Without seeing more of the code, my guess would be it is caused by your autoload in the store. With autoload set to true, when you call this "var loginStore = Ext.getStore('Login');", it actually is executing the load of the remote server without the extra parameters being set. Then you set the params and execute the load again, this time sending the request with the extra params as it should be. Try setting the autoload to false and see what happens.
-
31 Jul 2012 2:16 AM #6
Hi gcw07,
Thanks for your quick response.
Here is given the detail code:
===================================================================
Store page
===================================================================
Ext.define("NotesApp.store.Login", {
extend: "Ext.data.Store",
requires: [
'Ext.data.proxy.JsonP', "Ext.data.Model"
],
config: {
model: "NotesApp.model.Login",
proxy:{
type:"jsonp",
url:"http://10.4.3.199/SenchaTest/Default.aspx",
startParam: '',
pageParam: '',
limitParam: '',
extraParams: {
Un: false,
Pd: false
},
reader:{
type:"json",
rootProperty:"res"
}
},
autoLoad:true
}
});
===================================================================
Model Page
===================================================================
Ext.define("NotesApp.model.Login", {
extend: "Ext.data.Model",
config: {
// idProperty: 'id',
fields: [
{ name: 'userName', type: 'string' },
{ name: 'userPassword', type: 'string' },
{ name: 'ret', type: 'string' },
{ name: 'UID', type: 'string' },
{ name: 'L', type: 'string' },
{ name: 'OldA', type: 'string' },
{ name: 'Un', type: 'string' },
{ name: 'Pd', type: 'string' }
],
validations: [
{ type: 'presence', field: 'user_name', message:"Please Enter the User Name" },
{ type: 'presence', field: 'password', message:"Please Enter the Password" }
]
}
});
===================================================================
View Page
===================================================================
Ext.define("NotesApp.view.Login", {
extend:"Ext.form.Panel",
requires:"Ext.form.FieldSet",
alias:"widget.login",
id:"userForm",
config:{
scrollable:"vertical"
},
initialize: function(){
this.callParent(arguments);
var toolbar = {
xtype:"toolbar",
title:"Login",
docked:"top",
layout: {
pack: 'center'
}
};
var loginField = {
xtype:"textfield",
//label:"User Name",
placeHolder:"User@domain.com",
name:"userName",
id:"txt"
};
var passwordField = {
xtype:"passwordfield",
placeHolder:"password",
// label:"Password",
name:"userPassword",
id:"pwd"
};
var btnSubmit = {
xtype:"button",
text:"Submit",
ui:"confirm",
align:"center",
margin:"0 auto",
width:"90%",
height:"41px",
handler: this.onSubmitTap,
scope: this
};
this.add([toolbar, //loginStore,
{ xtype:"fieldset",
items:[loginField, passwordField]
},
{
xtype:"container",
layout:{
pack:"center"
},
items:[btnSubmit]
}
]);
},
onSubmitTap: function(){
//console.log("rrrrrrrrrr");
this.fireEvent("submitButtonCommand", this);
}
});
===================================================================
Control Page
===================================================================
In control page i am provide the code of submit button event handler
onSubmitButton: function(btn, evt){
// console.log("ssssssssssssss")
var txt = Ext.ComponentQuery.query('#txt')[0].getValue();
console.log(txt);
//
var pwd = Ext.ComponentQuery.query('#pwd')[0].getValue();
console.log(pwd);
var loginStore = Ext.getStore('Login');
// Apply the params to login store
loginStore.getProxy().setExtraParam('Un', txt);
loginStore.getProxy().setExtraParam('Pd', pwd);
loginStore.load();
// var ps=Ext.getStore('Login').getAt(0).get('userPassword');
var nm=Ext.getStore('Login').getAt(0).get('ret');
console.log("return value is="+nm);
//loginStore.load();
// if(txt==nm&&pwd==ps)
if(nm==1)
{
Ext.Msg.alert("Login in Successful");
this.activateLogin();
}
else{
nm = 0
// Ext.Msg.alert("Enter the correct User Name and password");
}
//this.activateLogin();
console.log("return is="+nm);
}
If possible Please help me .
Thanks & Regards
Vipin


Reply With Quote