Of course, the correct MIME media type for JSON is application/json
, but it's necessary to realize what type of data is expected in your application.
For example, I use Ext GWT and the server response must go as text/html but contains JSON data.
Client side, Ext GWT form listener
uploadForm.getForm().addListener(new FormListenerAdapter() { @Override public void onActionFailed(Form form, int httpStatus, String responseText) { MessageBox.alert("Error"); } @Override public void onActionComplete(Form form, int httpStatus, String responseText) { MessageBox.alert("Success"); } });
In case of using application/json response type, the browser suggests me to save the file.
Server side source code snippet using Spring MVC
return new AbstractUrlBasedView() { @SuppressWarnings("unchecked") @Override protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/html"); response.getWriter().write(json); } };