View Full Version : Getting error : 'You're trying to decode an invalid JSON String'

14 Oct 2011, 5:52 AM
Hi, I am a new extjs 4 user and have an error that I can't solve.

I use a form to connect to a database. I have a servlet that gets the form values and use them to connect to a database and return a xml file that contains all the tables name of this database. In a first time, I just want an alert message to confirm that it has worked. (The purpose is to fill a grid with the datas in future)

But the forms stay blocked on the waiting message and doen't show any alert message (fail or success).

Here is my js file

enabled: true
Ext.Loader.setPath('Ext.ux', 'lib/ux');


var db = [

var formPanel = Ext.create('Ext.form.Panel', {
renderTo: 'form-dbsource',
frame: true,
title:'Source database',
width: 340,
bodyPadding: 5,
waitMsgTarget: true,
fieldDefaults: {
labelAlign: 'right',
labelWidth: 85,
msgTarget: 'side'

items: [{
xtype: 'fieldset',
title: 'Source database informations',
defaultType: 'textfield',
defaults: {
width: 280
items: [{
fieldLabel: 'Address',
name: 'address',
emptyText : 'ex :',
allowblank : false,
value : ''
fieldLabel: 'Name',
name: 'databaseName',
allowblank : false,
value : 'testBD'
}, {
fieldLabel: 'User',
name: 'user',
//value : ""
value : 'sa'
}, {
fieldLabel: 'Password',
name: 'password',
inputType : 'password',
//value : ""
value : 'sa'
}, {
xtype: 'combobox',
fieldLabel: 'Type',
name: 'databaseType',
store: Ext.create('Ext.data.SimpleStore', {

fields : [
data: db
valueField : 'db',
displayField : 'db',
value : 'MSSQL',
typeAhead: true,
queryMode: 'local',
emptyText: 'Select a database type',
allowblank : false
xtype : 'hidden',
name : 'database',
value : 'source'

buttons: [{
text: 'Connection',
formBind: true, //if uncorrect field, datas not send
handler: function(){
url: 'outputDBSource.do',
//formBind : true,
submitEmptyText: false,
waitMsg: 'Sending Data...',
method: 'POST',
data: {},
success : function(form, action){
failure : function(form,action){
dataType: 'xml'


Here is the error message produce by firebug

'You're trying to decode an invalid JSON String:
<?xml version="1.0" encoding="ISO-8859-1"?>
<message success = "true">
<table> <tableName>table1</tableName> </table>
<table> <tableName>table2</tableName> </table>
<table> <tableName>table3</tableName> </table>
<table> <tableName>table4</tableName> </table>
<table> <tableName>table5</tableName> </table>
</tables> </message>'
when calling method: [nsIDOMEventListener::handleEvent]
[Stopper sur une erreur] originalHandler.handleEvent(event);
spy.js (ligne 798)

Here is outputDBSource.jsp file which produce the xml

<%@ page language="java" contentType="text/xml" trimDirectiveWhitespaces="true" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<?xml version="1.0" encoding="ISO-8859-1"?>
<message success = "true">
<c:forEach items="${listTables}" var = "name">

and here is my servlet response

req.setAttribute("listTables", listTables);
this.getServletContext().getRequestDispatcher("/outputDBSource.jsp").forward(req, resp);

I found other topics that suggest that the cause would be a wrong communication between js and server but can't find an answer to my specific case.

I hope you could help me. (and sorry for my bad english)

14 Oct 2011, 6:52 AM
Response found, the tag

<?xml version="1.0" encoding="ISO-8859-1"?>

was not necessary in the jsp.

Sorry to have posted this message.

27 Aug 2013, 2:23 AM
I have same problem how you solved this ?
I agree my response is a xml but not a JSON. and it doesn't have
<?xml version="1.0" encoding="ISO-8859-1"?> line too.
My xml response is as follows :

<I I="-1" NI="1169" X="F$-1$D"/>
<I I="420" NI="420" X="F$-1$D$S$"/>
<I I="-1" NI="1172" X="F$-1$D$VID$"/>
<I I="IP.txt" NI="IP.txt2" X="F$-1$D$T$"/>
<I I="1326" NI="1326" X="F$-1$D$F$"/>
<I NI="2013-08-27T04:29:11" X="F$-1$D$U$"/>
<I NI="2013-08-27T04:29:11" X="F$-1$D$-1$V$U$"/>
<I I="0" NI="0" X="F$-1$D$Ty$"/>
<I I="0" NI="0" X="F$-1$D$A$"/>
<I I="-1" NI="1172" F="1326" X="F$-1$D$-1$V"/>