Set Content Type to JSON causes open a download dialog display rather than populate into Data Table

Set Content Type to JSON causes open a download dialog display rather than populate into Data Table

peterwkcpeterwkc Posts: 21Questions: 0Answers: 0
edited October 2012 in General
Hello to all, I had set Content Type to JSON from Java Servlet causes open a download dialog display rather than populate into Data Table.What is the reason causes this error? I debug it using the firebug and nothing seems weird from there. The content type is application/json. I tested the function using Google Chrome, IE and Mozilla.

Another question is when first load the page, it make two requests to server. Why is the error?

JSP
[code]


$(document).ready(function()
{

$("#ticketList").dataTable({

"bProcessing" : true, // Enable processing indicator
"bServerSide" : true, // Configure data option - server or client
// Send XHR request to server
"sServerMethod": "POST", // GET or POST
"bSort" : true, // Enable sorting
"bFilter" : false,
"bAutoWidth" : true,
"sPaginationType" : "full_numbers", // Paginate Type -> two_button (Previous && Next)
// -> full_numbers (First, Previous, 1, 2, Next, Last)
"bLengthChange" : true,
"iDisplayLength" : 10,
"sAjaxSource" : "${context}/app.view?tn=Ticket.SearchTicket",
// Override $.getJson() get data from server
/*"fnServerData": function(sSource, aoData, fnCallback) {
$.ajax({ "dataType": 'json',
"type": "GET", // GET or POST to server for getting data
"url": sSource,
"data": aoData,
"success": fnCallback,
"error": function(jqXHR, textStatus, errorThrown) {
console.log(txtStatus, errorThrown); // use alert() if you prefer
}
});
}, */

"aoColumns": [
//mData mDataProp
{"mDataProp": "id"},
{"mDataProp": "category"},
{"mDataProp": "status"},
{"mDataProp": "assignee"},
{"mDataProp": "urgency"},
{"mDataProp": "action"}
]
/*
"fnRowCallBack" : function( nRow, aData, iDisplayIndex) {
// oTable.fnUpdate( newValue, rowPos, columnPos);
}*/
});
});




Search Ticket





Ticket Id:



Category:

Account
Invoice
Rates
No category



Urgency:

High
Medium
Low
No urgency



Status:

Unassigned
In Progress
Solved
No Status





Search Ticket













<!-- -->



Ticket ID
Category
Urgency
Status
Assignee
Action





Loading data from server



<!-- -->





[/code]

JAVA Servlet
[code]
JSONObject jsonObject = convertObject(ticketList);
taskResponse.setResponseText(jsonObject.toString());
response.setContentType("application/x-json");
response.getWriter().print(taskResponse.getResponseText());
[/code]

Please help. Thanks.

Replies

  • peterwkcpeterwkc Posts: 21Questions: 0Answers: 0
    Please help. It is urgent.
  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    The content type for your JSON looks a little off to me. The fact that the browser doesn't know what to do with it also suggests that it is wrong. Try `application/json` .

    > Another question is when first load the page, it make two requests to server. Why is the error?

    No idea - I think we'd need a link to debug why that is.

    Allan
This discussion has been closed.