PDA

View Full Version : AJAX form post content type problem



kolaloka
1 Feb 2010, 6:59 AM
Hi All,

I have a form which I want to post to a Java servlet. The problem is this gets into POST header (from Firebug):
"Content-Length 934
Content-Type text/plain; charset=UTF-8"
while the servlet would require
"Content-Type application/x-www-form-urlencoded; charset=UTF-8"
to be able to decode POST data. Which is also set in Ext.lib.Ajax settings (Firebug shows them)
The application is available here, Javascript is readable:
http://att-it.homelinux.net:22880/kvg/index.html
1. click Menetlevel urlap in bottom right
2. select something from the upper combo
3. click Menetlevel megnyitasa
The form (whithout items, but with remaining copy-past text :) ) and submit button:
this.nyitGomb=new Ext.Button({
text: 'Menetlevel megnyitasa',
disabled:false,
handler: function(){
Alk.menetlevelUrlap.getForm().submit({url:Alk.configuration.servlet_base+'menetlevelnyit', waitMsg:'Megnyitas...'});
}
});
this.menetlevelUrlap=new Ext.form.FormPanel({
id:'card-1',
frame: true,
title:'Menetlevel urlap',
labelAlign: 'right',
labelWidth: 85,
waitMsgTarget: true,

// configure how to read the XML Data
reader : new Ext.data.XmlReader({
record : 'contact',
success: '@success'
}, [
{name: 'first', mapping:'name/first'}, // custom mapping
{name: 'last', mapping:'name/last'},
'company', 'email', 'state',
{name: 'dob', type:'date', dateFormat:'m/d/Y'} // custom data types
]),
items:[... somewhere here buttons:[this.nyitGomb,this.ujGomb], ]
});

What is the problem?

thank you in advance. Best regards: Balázs

realjax
1 Feb 2010, 8:04 AM
Well.. can't really make heads or tails from your message.. however, you could try setting
standardSubmit: true

in your formpanel.

kolaloka
1 Feb 2010, 11:29 PM
Hi Realjax,

This doesn't help. It makes real form posting instead of AJAX, which is even worse. I try to clarify my former description.

I have a FormPanel which I want to post to a Java servlet using AJAX, so Javascript code of the page would process the response. The post occurs, but the servlet is unable to process the post data. Observing the POST header in Firebug shows this in the header:

"Content-Length 934
Content-Type text/plain; charset=UTF-8"

while the servlet would require

"Content-Type application/x-www-form-urlencoded; charset=UTF-8"

to be able to decode POST data.

The Ext.lib.Ajax settings (shown if Firebug) contain

Ext.lib.Ajax.defaultPostSettings="application/x-www-form-urlencoded; charset=UTF-8"
Ext.lib.Ajax.useDefaultHeader=true

so this content-type is overwritten somewhere to the wrong text/plain.

The application is available here, Javascript is readable:
http://att-it.homelinux.net:22880/kvg/index.html
1. click Menetlevel urlap in bottom right
2. select something from the upper combo
3. click Menetlevel megnyitasa

The form (whithout items):

this.nyitGomb=new Ext.Button({
text: 'Menetlevel megnyitasa',
disabled:false,
handler: function(){
Alk.menetlevelUrlap.getForm().submit({url:Alk.configuration.servlet_base+'menetlevelnyit', waitMsg:'Megnyitas...'});
}
});
this.menetlevelUrlap=new Ext.form.FormPanel({
id:'card-1',
frame: true,
title:'Menetlevel urlap',
labelAlign: 'right',
labelWidth: 85,
waitMsgTarget: true,
items:[... somewhere here buttons:[this.nyitGomb,this.ujGomb], ]
});

What is the problem?

thank you in advance. Best regards: Balázs

realjax
2 Feb 2010, 12:21 AM
Hmm.. Looking at your app, posting seems to work just fine. The errormessage returned from your server however states:
'Column ambiguously defined ', which has more to do with the way you set up your queries..

kolaloka
2 Feb 2010, 3:11 AM
Hi Realjax,

This is tricky. Code from servlet is

String fej_menlevfaz = request.getParameter("fej_menlevfaz");
try {
db.connect("gis");
PreparedStatement ps=db.prepareStatement(
"SELECT SORSZAM, JARMUAZ, RENDSZAM || ' ' || TIPUS AS KIIRVA, RAKKM, ARUTKM, KM, TOMEG FROM KVG_MENLEVF M JOIN KVG_JARMU J ON M.JARMUAZ=J.JARMUAZ WHERE MENLEVFAZ ="+fej_menlevfaz);

and here fej_menlevfaz is Java null, so the SQL condition

WHERE MENLEVFAZ = null

is invalid. However, if you look at the posted data,

"fej_menlevfaz=2&fej_jarmuaz=&fej_sorszam=&fej_rakkm=&fej_arutkm=&"

so

request.getParameter("fej_menlevfaz");

Java line should return "2". This does not occur on an other ExtJS
application we developed. Here other type of AJAX post is issued, and POST
content-type is application/x-www-form-urlencoded
JS code fragment for this other post is

this.store = new Ext.data.JsonStore({
fields: ['HRSZO', 'TIRSZ', 'TELNE', 'KONEV', 'KOJEL', 'H
ZSZA', 'HRCAZ', 'HRSAZ'],
root: 'gyoker',
url: Dpk.configuration.servlet_base+'thrc'
});
this.store.load({
params: {
dbuser: 'dpk_' + ApplicationConfig.cityParam,
hrsaz: ApplicationConfig.hrsazParam
}
});

So the problem lies definitely around form post settings.

Thank you, best regards: Balázs

kolaloka
2 Feb 2010, 5:00 AM
I've decided to omit normal form submission and make AJAX post by hand. To achieve this, I've begun to examine Ext.Ajax and found the solution:
Ext.Ajax.defaultHeaders={
'Content-Type': 'application/x-www-form-urlencoded; charser=UTF-8'
};
Actually charset=UTF-8 is not needed, Ext puts it there. Now it works, the servlet processes the request.

best regards: Balázs