PDA

View Full Version : x-json response tries to open as a file



Dariusz
29 Nov 2007, 9:51 AM
I am sending a form to the server and getting a x-json response back, which is actualy only a confirmation for my 'Confirmation Box' if either the form request was ok or not.

Here is my ExtJS:


Ext.onReady( function(){

Ext.QuickTips.init();
Ext.QuickTips.enable();

Ext.form.Field.prototype.msgTarget = 'under';

/* Address data */
var addressCodeReader = new Ext.data.JsonReader({
totalProperty: "results",
root: "rows",
id: 'addressID'
},[
{name: 'addressID', type: 'int'},
{name: 'address', type: 'string'},
{name: 'description', type: 'string'}
]
);

var addressStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy( { url: '/IpnServlet?action=readAddressCodes' } ),
reader: addressCodeReader
});


/* Category data */
var ipnCategoryReader = new Ext.data.JsonReader({
totalProperty: "results",
root: "rows",
id: "categoryID"
},[
{name: 'categoryID', type: 'int'},
{name: 'category', type: 'string'}
]
);

var ipnCategoryStore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy( { url: '/IpnServlet?action=readIpnCategory' } ),
reader: ipnCategoryReader
});



var ipnForm = new Ext.FormPanel({
el: 'createIpn',
id: 'createIpn',
method: 'post',
labelAlign: 'left',
labelWidth: 110,
frame: true,
title: 'Submit IPN',
bodyStyle: 'padding:5px 5px 0',
height: 600,
width: 700,
scope: this,
fileUpload: true,
enctype: 'multipart/form-data',

items: [{
xtype: 'fieldset',
title: 'Section Information',
autoHeight: true,
//defaults: { width: 430 },
defaultType: 'textfield',

items :[
new Ext.form.ComboBox({
fieldLabel: 'Address Code',
store: addressStore,
hiddenName: 'addressID',
displayField: 'address',
valueField: 'addressID',
typeAhead: true,
triggerAction: 'all',
forceSelection: true,
emptyText: 'Select your address code...',
selectOnFocus: true,
allowBlank: false,
//width: 190
anchor: '98%'
})
,
new Ext.form.ComboBox({
fieldLabel: 'Ipn Code',
store: ipnCategoryStore,
hiddenName: 'categoryID',
displayField: 'category',
valueField: 'categoryID',
typeAhead: true,
triggerAction: 'all',
forceSelection: true,
emptyText: 'Select the IPN Code...',
selectOnFocus: true,
allowBlank: false,
//width: 190
anchor: '98%'
})
]
},{
xtype: 'fieldset',
title: 'IPN Information',
autoHeight: true,
//defaults: { width: 430 },
defaultType: 'textfield',
items :[
{
fieldLabel: 'IPN Title',
allowBlank: false,
name: 'title',
anchor: '98%'
},
{
xtype: 'textfield',
fieldLabel: 'Upload file',
inputType: 'file',
width: 400,
blankText: 'Please choose a file',
name: 'uploadFile'
},
{
xtype: 'htmleditor',
height: 100,
enableColors: false,
enableAlignments: false,
enableFont: false,
enableFontSize: false,
enableSourceEdit: false,
name: 'description',
fieldLabel: 'Description',
allowBlank: false,
anchor: '98%'
}
]
}
],

buttons: [{
text: 'Save',
type: 'submit',
name: 'send',
disabled: false,
handler: saveIPN
},{
text: 'Cancel'
}]

});


function saveIPN() {

ipnForm.form.submit({
url : '/IpnServlet?action=saveIPN',
waitMsg: 'Saving Data...',

success: function( result, request )
{
Ext.Msg.show({
title: 'Confirmation',
msg: 'Your data has been updated!',
buttons: Ext.Msg.OK,
fn: function(){
result.reset();
showIPNS();
}
});
},
failure: function( result, request )
{
Ext.Msg.show({
title: 'Failure',
msg: 'You must fill out the form before sending it!',
buttons: Ext.MessageBox.OK,
});
}

});
}


function showIPNS()
{
document.location = "/IpnServlet?action=ipn";
}


ipnForm.render();

});


The question is, why the browser tries to deal the response (x-json) as an application?

If I take a look in the firebug, I can see the following output:



Content-Type application/x-json
Transfer-Encoding chunked
Request Headers

Gecko/20071115 Firefox/2.0.0.10
Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language en-gb,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive

Cookie JSESSIONID=CF27B364FE20E27410115A3F14766CAB


and the reponse is this:


{"success":true}


So, actualy everything seems pretty normal, but why does it treat it as an application?

Thanks,
Dariusz

hendricd
29 Nov 2007, 9:56 AM
That would be appropriate for a JSON response. ;)

Dariusz
29 Nov 2007, 10:03 AM
Thanks, but still doesn't help me...

santosh.rajan
29 Nov 2007, 10:06 AM
success: function( result, request )
{
Ext.Msg.show({
title: 'Confirmation',
msg: 'Your data has been updated!',
buttons: Ext.Msg.OK,
fn: function(){
result.reset();
showIPNS(); /////// THIS FUNCTION HERE
}
});
},
failure: function( result, request )
{
Ext.Msg.show({
title: 'Failure',
msg: 'You must fill out the form before sending it!',
buttons: Ext.MessageBox.OK,
});
}

});
}


function showIPNS()
{
document.location = "/IpnServlet?action=ipn"; /////// IS CHANGING WINDOW LOCATION
}

tryanDLS
29 Nov 2007, 10:23 AM
Why are you setting a content-type that indicates an application instead of something like 'text/json'?

Dariusz
30 Nov 2007, 5:34 AM
Why are you setting a content-type that indicates an application instead of something like 'text/json'?

That's it! I just took out the 'setting' and it worked! :)

Thanks!
Dariusz