I'm facing issues with ExtJS 4.1.3. In my ExtJS controller, I call an ajax request like this :
Ext.Ajax.request(
{
url: '/my/url/method.do'
,timeout: 1800000
,jsonData: param
,success:function(response)
{
var jsonData = Ext.JSON.decode(response.responseText);
alert(jsonData);
// some code
}
,failure:function(response)
{
// some code
}
,scope:this
}
);
This is the method called in spring :
@RequestMapping(value = "/my/url/method.do")
public @ResponseBody String method(Locale userLocale, @RequestBody Param[] param) {
return "string" + "<br/>" + "string";
}
It works well on Google Chrome and IE but not on Firefox. Indeed, I get the following error :
Ext.Error: You're trying to decode an invalid JSON String: string<br/>string
And I don't know why it doesn't work because if I execute the following code in the Firefox console, it works :
Ext.JSON.decode("string<br/>string")
So if anyone could help me, I would be grateful !
Thanks for your answers.
This website http://jsonlint.com/ indicates "string<br/>string"
as a valid JSON string. But it is a "false" JSON validation cause it is not proper JSON format.
I solved my problem adding produce="application/json"
in the @RequestMapping
annotation of the controller. So now Ext.JSON.decode() works even with Firefox.
I could also send back an object serializable with the ajax request and then decode the response to get the data (with my string in it) because Spring automatically serialize object to JSON.