Setup:
I have a datatable, each one is interactive. When you click on a line, an ajax call is made, which returns some data. Sometimes ajax call takes a little time, depending on the amount of data returned. Everything is working fine.
Problem:
The problem arises when lines are quickly pressed one after another. In short, before the previous ajax call is returned, if I click on the line (i.e. a new ajax call will be made), I get an error.
Uncaught TypeError: Property 'callback' of object [object Window] is not a function
(ajax call returns JSONP data)
It seems that for some reason ajax calls are mixed (?), But I'm not sure about that. Can someone please tell me why this is happening?
Please let me know if additional information is needed to clarify the problem.
thanks
EDIT 1:
Here is the ajax code:
$.ajax({ type: "GET", url: 'http://' + myserver + ':8080/someurl/' + my_param, contentType: "application/json", dataType: "jsonp", jsonpCallback: 'callback', success: function(data) { // Inside here, I am doing some Datatables stuff. var myTable = $('#my_table').dataTable( { "bJQueryUI" : true, "bSort" : false, "bFilter" : false, "bPaginate": true, "bProcessing": true, "bScrollCollapse": true, "bInfo": false, "bDestroy": true, "aaData": samples, "sEmptyTable": "No sample listings avaiable", "iDisplayLength": number, "bLengthChange": false, "bAutoWidth": false, . . . }
EDIT 2:
Here is the class that assigns callback its name. If the default callback is null, it assigns a default callback. But it looks like the default callback is always zero by default, and therefore it always assigns a βcallbackβ.
public class MappingJacksonJsonpConverter extends MappingJacksonHttpMessageConverter { @Override protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType()); JsonGenerator jsonGenerator = this.getObjectMapper() .getJsonFactory() .createJsonGenerator(outputMessage.getBody(), encoding); try { String jsonPadding = "callback"; if (object instanceof JsonObject) { String jsonCallback = ((JsonObject) object).getJsonCallback(); if (jsonCallback != null) { jsonPadding = jsonCallback; } } jsonGenerator.writeRaw(jsonPadding); jsonGenerator.writeRaw("("); this.getObjectMapper().writeValue(jsonGenerator, object); jsonGenerator.writeRaw(")"); jsonGenerator.flush(); } catch (JsonProcessingException ex) { throw new HttpMessageNotWritableException("Could not write JSON: " + ex.getMessage(), ex); } } }
And this class refers to mvc-servlet.xml as follows:
<mvc:message-converters> <bean class="citygrid.feedmanager.web.converter.MappingJacksonJsonpConverter"> <property name="supportedMediaTypes"> <list> <value>application/x-javascript</value> </list> </property> </bean> </mvc:message-converters>