PDA

View Full Version : [CLOSED][3.??] Ext.data.Store param POST



globalab
28 Jun 2009, 9:55 AM
Hi guys,

First of all, I've already posted this on this thread Ext.data.Store param POST (http://www.extjs.com/forum/showthread.php?t=69707), but I'm not recieving any answer/suggestion at all, so i came here to expose my problem, hope someone can help me with this

I have a form with a combobox that is configured as follows

The store:


var fields = [
{ name: 'Name', type: 'string' },
{ name: 'FullName', type: 'string' }
];
var proxy = new Ext.data.HttpProxy({
url: Praedator.Conf.ServiceInvoker,
method: 'POST'
});
var store = new Ext.data.JsonStore({
proxy: proxy,
reader: new Ext.data.JsonReader({
root: 'Result',
successProperty: 'Success',
idProperty: 'FullName'
}, Ext.data.Record.create(fields)),
baseParams: {
Service: 'Praedator.Framework.Core.Domain.Tools.Import.IImporterService',
Method: 'GetEntities'
},
remoteSort: true,
autoLoad: true,
autoSave: false
});



and the combobox configuration


items: [{
xtype: 'combo',
fieldLabel: 'Select an entity',
emptyText: 'Select...',
displayField: 'Name',
valueField: 'FullName',
allowBlank: false,
forceSelection: true,
disableKeyFilter: true,
store: store
}],


and in the server i'm recieving this


2009-06-24 13:06:08,192 [6] DEBUG HttpAdapter - Request string readed: Service=Praedator.Framework.Core.Domain.Tools.Import.IImporterService&Method=GetEntities&Depth=2

when it's suposed to recieve something like this (this is a request for another service wich im doing via Ext.Ajax.request)

2009-06-24 13:06:03,165 [6] DEBUG HttpAdapter - Request string readed: {"Service":"Praedator.Framework.Core.Domain.IEnumDescriptorService","Method":"GetEnumDescriptions","Parameters":null}


Am i doing something wrong? I've revised it but don't find where the problem is, the strange part of it, is that this the only place where i have this problem, the rest of stores are working as supposed.



Thanks


P.S. I'm sorry if my english is hard to read :">

jsakalos
28 Jun 2009, 11:05 AM
Is the request still sent using GET? If so, upgrade to the latest Ext 3 svn. There is a note in the thread you refer to that it had been a bug that has been already fixed.

globalab
28 Jun 2009, 1:04 PM
Hi Jozef,

First of all, thak you for your quick answer :D,


About your message ' have to say 3 times yes :),

yes, it is still sending a GET instead of a POST after I'm telling I want a POST

yes, i've seen the message that you refer,

and yes, I also commented that already tried from trunk,


I've tried it today from svn looking for it to be fixed but is still making the GET :((.


Thanks

jsakalos
28 Jun 2009, 1:20 PM
Then it looks like a bug. Moving the thread to Bugs so that devel team can investigate/fix it.

mjlecomte
28 Jun 2009, 1:42 PM
When I paste the below into firebug I see the request go out via POST. Am I missing something?



var fields = [{
name: 'Name',
type: 'string'
}, {
name: 'FullName',
type: 'string'
}];
var proxy = new Ext.data.HttpProxy({
url: 'test.php',
method: 'POST'
});
var store = new Ext.data.JsonStore({
proxy: proxy,
reader: new Ext.data.JsonReader({
root: 'Result',
successProperty: 'Success',
idProperty: 'FullName'
}, Ext.data.Record.create(fields)),
baseParams: {
Service: 'Praedator.Framework.Core.Domain.Tools.Import.IImporterService',
Method: 'GetEntities'
},
remoteSort: true,
autoLoad: true,
autoSave: false
});

mjlecomte
28 Jun 2009, 1:44 PM
Also note, your reader configuration will be ignored as shown. Either use a Ext.data.Store with the reader you configured, or use a JsonStore, and pass in the JsonReader configs to the store. The JsonStore implicitly creates a JsonReader. See the Docs: http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.data.JsonStore

globalab
28 Jun 2009, 5:00 PM
Hi mjlecomte,

Thanks for the quick answer =D>, I've tried both, with an Ext.data.Store as follows



var fields = [{
name: 'Name',
type: 'string'
}, {
name: 'FullName',
type: 'string'
}];
var proxy = new Ext.data.HttpProxy({
url: Praedator.Conf.ServiceInvoker,
method: 'POST'
});
var store = new Ext.data.Store({
proxy: proxy,
reader: new Ext.data.JsonReader({
root: 'Result',
successProperty: 'Success',
idProperty: 'FullName'
}, Ext.data.Record.create(fields)),
baseParams: {
Service: 'Praedator.Framework.Core.Domain.Tools.Import.IImporterService',
Method: 'GetEntities',
Parameters: null,
Depth: Praedator.Conf.DefaultFindDepth
},
remoteSort: true,
autoLoad: true,
autoSave: false
});


and a pure config Ext.data.JsonStore



var store = new Ext.data.JsonStore({
// store config
url: Praedator.Conf.ServiceInvoker,
method: 'POST',
baseParams: {
Service: 'Praedator.Framework.Core.Domain.Tools.Import.IImporterService',
Method: 'GetEntities',
Parameters: null,
Depth: Praedator.Conf.DefaultFindDepth
},
autoLoad: true,
autoSave: false,
// reader config
root: 'Result',
successProperty: 'Success',
idProperty: 'FullName',
fields: [{ name: 'Name', type: 'string' }, { name: 'FullName', type: 'string' }]
});


with sadly, the same result :((, it comes to the server as a GET request :(

the code of my window is this if it helps (only the initComponent method):



initComponent: function(){
if (PLOG.isDebugEnabled()) {
PLOG.debug('[Importer.initComponent] <-');
}
var store = new Ext.data.JsonStore({
// store config
url: Praedator.Conf.ServiceInvoker,
method: 'POST',
baseParams: {
Service: 'Praedator.Framework.Core.Domain.Tools.Import.IImporterService',
Method: 'GetEntities',
Parameters: null,
Depth: Praedator.Conf.DefaultFindDepth
},
autoLoad: true,
autoSave: false,
// reader config
root: 'Result',
successProperty: 'Success',
idProperty: 'FullName',
fields: [{ name: 'Name', type: 'string' }, { name: 'FullName', type: 'string' }]
});

Ext.apply(this, {
layout: 'fit',
bbar: new Ext.ux.StatusBar({
id: 'importerStatusbar',
defaultText: '',
busyText: 'Procesando...'
}),
items: [{
xtype: 'tabpanel',
activeItem: 0,
items: [{
title: 'Generar Layout',
xtype: 'form',
frame: true,
border: true,
labelWidth: 140,
defaults: {
anchor: '95%',
labelAlign: 'right'
},
items: [{
xtype: 'combo',
fieldLabel: 'Seleccione la entidad',
emptyText: 'Seleccione una entidad...',
displayField: 'Name',
valueField: 'FullName',
allowBlank: false,
mode: 'local',
forceSelection: true,
disableKeyFilter: true,
store: store
}],
buttons: [{
text: 'Generar Layout',
handler: this.getLayout,
scope: this
}]
}, {
title: 'Importar archivo',
xtype: 'form',
id: 'layoutUploadForm',
fileUpload: true,
monitorValid: true,
frame: true,
border: true,
labelWidth: 120,
defaults: {
anchor: '95%',
labelAlign: 'right'
},
items: [{
xtype: 'fileuploadfield',
allowBlank: false,
fieldLabel: 'Archivo de datos'
}, {
xtype: 'checkbox',
hideLabel: true,
boxLabel: 'Actualizar registros existentes? (sobreescritura)'
}],
buttons: [{
text: 'Importar archivo',
handler: this.uploadLayout,
scope: this
}]
}]
}]
});
Praedator.Tools.Importer.MainForm.superclass.initComponent.apply(this, arguments);
this.show();
if (PLOG.isDebugEnabled()) {
PLOG.debug('[Importer.initComponent] ->');
}
}



Am I doing something wrong?

Thank you MJ for the help.

mjlecomte
28 Jun 2009, 6:54 PM
Let's try to work this from more common ground first ok?

In firefox I go here:
http://extjs.com/deploy/ext-3.0-rc2/examples/window/hello.html
See attachment 1.

I open firebug console and post the code show from here:
http://extjs.com/forum/showthread.php?p=349718#post349718
See attachment 2.

Notice the 2nd line of the console shows POST in red for me. So the request does in fact go out via POST for me. What do you get?

mjlecomte
28 Jun 2009, 6:57 PM
Let me expand that screenshot from firebug so you can see the url and the POST.

globalab
28 Jun 2009, 7:50 PM
Thanks MJ!!!

I'm starting to see the light :), you're absolutely right, it's doing a POST :s!!! but it is sending it like it were doing a Ext.urlEncode :-?

Why is sending this way?


Thanks MJ!!!

mjlecomte
28 Jun 2009, 11:13 PM
I'm not sure what you mean.

globalab
29 Jun 2009, 6:08 AM
Sorry, here is my screenshot, see that it is sending the data url encoded instead of a json encoded.


Thanks

Condor
29 Jun 2009, 6:12 AM
I don't always trust Firebug when it comes to POST data.

Could you check with Fiddler if this is really what is being sent?

mjlecomte
29 Jun 2009, 6:13 AM
Sometimes it shows up like that for me also, not sure what the deal is there. Regardless of that point, does the information show up in POST or GET at your server?

globalab
29 Jun 2009, 6:46 AM
Thans Condor,

I have checked it with fiddler and yes, this is what it's been sending to the server:

Service=Praedator.Framework.Core.Domain.Tools.Import.IImporterService&Method=GetEntities&Depth=2


Ok, lets put this way MJ, ths store is sending a POST to the server, that is clear, i was on an error, it always sent a POST, I've thought that because I'm recieving the string shown above (url encoded) when i was specting it as a json encoded data.

My problem now is tha my back-end process an input of this form

{ "Service":"Praedator.Framework.Core.Domain.Tools.Import.IImporterService", "Method":"GetEntities","Depth":"2" }


not this

Service=Praedator.Framework.Core.Domain.Tools.Import.IImporterService&Method=GetEntities&Depth=2

Thanks Condor & MJ.

mjlecomte
29 Jun 2009, 6:51 AM
Let's try to work this from more common ground first ok?

In firefox I go here:
http://extjs.com/deploy/ext-3.0-rc2/examples/window/hello.html
See attachment 1.

I open firebug console and post the code show from here:
http://extjs.com/forum/showthread.php?p=349718#post349718
See attachment 2.

Notice the 2nd line of the console shows POST in red for me. So the request does in fact go out via POST for me. What do you get?

Can you first respond to this post so we have some common starting point? Do you see the same thing or not?

globalab
29 Jun 2009, 6:54 AM
Yes, as i'd mentioned in my last message /:), it is sending a via POST.

mjlecomte
29 Jun 2009, 6:55 AM
The other thing you can do is make an isolated test case, not part of some (preconfigured) class. Let's try to remove some of the unknowns here (things I can not reproduce the same as you)...

mjlecomte
29 Jun 2009, 6:56 AM
Yes, as i'd mentioned in my last message /:), it is sending a via POST.

That part I am clear about. It is always sending POST. But going to the extjs.com site and pasting in firebug console does it then send it as string or encoded?

globalab
29 Jun 2009, 7:17 AM
Ok ok, sorry MJ :"> i haven't understand want you ask me to do :)).

I've tried and yes, its working on that link!!! :s

but when i do the same in my app it sends as url encoded :((



Thanks MJ

mjlecomte
29 Jun 2009, 9:21 AM
How about testing that against the same ext/examples/ on your localhost (basically outside of your project)?

globalab
29 Jun 2009, 10:43 AM
I'd tried, and it works ok in the examples :s, thus is my fault :(( but can't find why its happening :-/

I have searched in the docs but can't find a configuration tha might cause this

jsakalos
29 Jun 2009, 10:47 AM
In that case, post a working showcase (http://extjs.com/forum/../learn/Ext_Forum_Help#Posting_a_working_showcase), we'll take a look.

globalab
29 Jun 2009, 11:48 AM
Thanks MJ, Jozef

I was preparing the working showcase and found that this line was the source of the error:



Ext.lib.Ajax.defaultPostHeader = 'application/json';


I deleted and test my showcase...and it ran!!! :D,

but when i tried with my app again the error was there again :((, I will follow this error, and tell you what i'd found, it seems that the error is hidden in my code (i can't set it here because of the size, around 7k lines :s) :(



Again thank you guys, for your enormous patience :D =D>

globalab
29 Jun 2009, 12:48 PM
UPDATE:

Ok, It's me again (i will make you dream me!! :)))

I have followed the suggestion from Condor (thanks Condor for the Fiddler tip :)) and monitored with Fiddler, and it surprissed me that Fiddler says: FireBug is lying :s

i've attatched the scrrenshots :

1. firebug saying is a post with json encoded data.
2. fiddler for the same request showing a url encoded data.


hope this info helps...


P.S. MJ, I'm testing against the link you gave me (http://extjs.com/deploy/ext-3.0-rc2/examples/window/hello.html) and with the code in #5 in this post.

jsakalos
29 Jun 2009, 1:02 PM
You know, I use Ext for more than 2 years and I have PHP backend that processes only POSTed data. I've never had any problems, from yui-ext, through 1.x, 2.x, up to 3.0 related to not POSTing but GETting data, neither with "Firebug lying".

Take please this example: http://examples.extjs.eu/?ex=gridintab, run it agains Ext 3 latest SVN and if it runs correctly then the bug must be in your code.

globalab
29 Jun 2009, 1:26 PM
Sorry Jozef,

I'm not suggesting nothing about Ext, it is a great tool.


I'd tried your sample, but i get the same, this is fiddler raw inspection data for the grid:



POST /Cognitum/get-grid-data.php HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.33 Safari/530.5
Referer: http://localhost/Cognitum/grid.html
Content-Length: 16
Origin: http://localhost
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Language: es-ES,es;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

start=0&limit=10

as you can read, it is sending the data rul encoded, not json econded, why am i sying that? because my back only processes json encoded data.


here is a post correctly sent via Ext.Ajax.request:


POST /Cognitum/(S(g5zu1b2bnqzw1c55rfhnnjji)F(rFoGNz07JUmbYXWoa6oRgxD-igV977F2PPnhjUDzRXhrQKoC6-N-K7Zq9anN_3tPjiHL41y-b9Lj36ug7QMxoHnqOY_zeZ3vUJPQrkvRwKQ3MLIevQ2xF1gLOOgQRG1-0))/Service/ServiceInvoker HTTP/1.1
Host: localhost
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.33 Safari/530.5
Referer: http://localhost/Cognitum/(S(g5zu1b2bnqzw1c55rfhnnjji)F(rFoGNz07JUmbYXWoa6oRgxD-igV977F2PPnhjUDzRXhrQKoC6-N-K7Zq9anN_3tPjiHL41y-b9Lj36ug7QMxoHnqOY_zeZ3vUJPQrkvRwKQ3MLIevQ2xF1gLOOgQRG1-0))/Default.aspx
Content-Length: 117
Origin: http://localhost
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Language: es-ES,es;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

{"Service":"Praedator.Framework.Core.Domain.IEnumDescriptorService","Method":"GetEnumDescriptions","Parameters":null}


Hope this info helps

Thanks guys

jsakalos
29 Jun 2009, 2:36 PM
Now I'm baffled.

POST (http://en.wikipedia.org/wiki/POST_%28HTTP%29) has nothing to do with JSON, it is HTTP request method similar to GET (where key-value-pairs are part of the request url) but safer. If POST is used key-value-pairs are not part of the request url and the request size is limited by the server configuration only.

JSON (http://json.org) is Javascript Object Notation and has nothing to do with POST except that, if you do so, a json encoded object (string) can be value of one of the key-value-pairs POSTed.

globalab
29 Jun 2009, 3:03 PM
Mmmm... :-|


I was talking of the difference between POSTing the data using Ext.util.JSON.encode and POSTing it with Ext.urlEncode as it seems to be doing, not pretending to mix two diferent concepts (by the way, thanks for the links but i already know what means each of these concepts Jozef).

jsakalos
29 Jun 2009, 3:52 PM
I still don't understand the point. If we're going to POST anything we need to prepare key-value-pairs and then POST them; if one or more of the values (not keys) is json encoded is irrelevant. Or we have a standard form with method POST that we just submit. This is at the lowest level.

If we're talking about Ext.Ajax.request setup for method POST and called with argument options that has options.params object, the key/value pairs of options.params become key-value-pairs of the POST request.

E.g.:


Ext.Ajax.request({params:{
key1:'value1'
,key2:'value2'
}})
will become $_POST["key1"] = "value1" and $_POST["key2"] = "value2" at the server (in PHP language). The data travel between client and server URL encoded as per HTTP spec (see wiki article I've posted the link of).

globalab
29 Jun 2009, 8:05 PM
Thanks for the quick answer Jozef,

Lets put things this way, the method that the Store is using is using to send the data (POST) is clear to me (as i have said before), here is no problem, i agree with you that is a method to send the data, my question, doubt, problem is why is it sending encoded as a url and not as an object encoded in a string as the other methods i'm using?, what am i doing wrong?


Again, thank you for the help, and more for your patience, you must be in terrible pain helping me :)

jsakalos
29 Jun 2009, 11:49 PM
Can you post a sample of data (string, whatever) what you like to have at server?

globalab
1 Jul 2009, 9:01 AM
I've resolved it.

Thanks MJ, Condor, Saki

jsakalos
1 Jul 2009, 9:04 AM
Can you post how? It could be useful for other users.

mjlecomte
1 Jul 2009, 10:28 AM
Can you post how? It could be useful for other users.

Yes, please post your resolution as undoubtedly someone else will come across your thread later through searches.

Jokie
3 Jul 2009, 1:37 PM
Please post your solution as I am having the same problem, where if the header is set to json intead of json encoding it url encodes

globalab
3 Jul 2009, 3:49 PM
Hi Jokie,

I know it is not a real solution since i'd only patched the problem, but at the time i was pressed with the time and it worked for me, hope this works for your problem too.

I'd made a class that extends Ext.data.HttpProxy and overloads the load method, here is my code



load: function(params, reader, callback, scope, arg) {
if (this.fireEvent("beforeload", this, params) !== false) {
var o = {
params: params || {},
request: {
callback: callback,
scope: scope,
arg: arg
},
reader: reader,
callback: this.loadResponse,
jsonData: params || {},
scope: this
};
if (this.useAjax) {
Ext.applyIf(o, this.conn);
if (this.activeRequest) {
Ext.Ajax.abort(this.activeRequest);
}
this.activeRequest = Ext.Ajax.request(o);
} else {
this.conn.request(o);
}
} else {
callback.call(scope || this, null, arg, false);
}
}


hope it helps you.

Jokie
4 Jul 2009, 6:22 PM
Thank you globalab

I hope this will be fixed on the release, I have been trying to test the RESTful Store Example using a .NET WCF service but since to POST json the Content-Type is set to

application/x-www-form-urlencoded
and if you change it to
application/json then one ends up with urlencoded data rather than json. Which throws of the webservice.