When your smartGWT data source calls this URL:
http://www.smartclient.com/smartgwt/showcase/data/dataIntegration/json/contactsData.js
(If the data source makes a call to a Java application, skip to the bottom of this answer)
Your data source query will include a GET parameter called a callback, which looks like this:
callback=isc.Comm._scriptIncludeReply_0
script, contactsData.js, you will need to commit this GET parameter.
contactsData.js will need to enable the library to retrieve the parameters from the URL:
Function to get javascript parameters:
function getParameter ( queryString, parameterName ) { // Add "=" to the parameter name (ie parameterName=value) var parameterName = parameterName + "="; if ( queryString.length > 0 ) { // Find the beginning of the string begin = queryString.indexOf ( parameterName ); // If the parameter name is not found, skip it, otherwise return the value if ( begin != -1 ) { // Add the length (integer) to the beginning begin += parameterName.length; // Multiple parameters are separated by the "&" sign end = queryString.indexOf ( "&" , begin ); if ( end == -1 ) { end = queryString.length }
Function for getting jQuery parameters
http://ajaxcssblog.com/jquery/url-read-request-variables/
After you get the value of the callback parameter, you will write the function name with JSON as the parameter in the response body, for example:
isc.Comm._scriptIncludeReply_0({"item": [ {"id": "1","name": "Monkey"}, {"id": "2","name": "Tree"}, {"id": "3","name": "Banana"} ] })
Thus, the javascript code will look something like this:
Response.Write(getParameter(URLrequestFromDatasourceString,"callback") + " ( " + JSON + " )" );
Java
If your smartGWT data source calls the Java application URL:
http://www.smartclient.com/getJson.htm
Your Java controller will do the same, but much easier
String callbackString = request.getParameter("callback"); response.setContentType("text/X-JSON"); response.getWriter().write( callbackString + " ( " + JSONstring + " ) " ); response.setStatus(HttpServletResponse.SC_OK);
Also, here is the link to the blog post about the problem