title: Why does a single Ajax call work fine, but consecutive Ajax calls fail?
body: <p><strong>Setup:</strong></p>
  
  <p>I have a Datatable, whose each row is clickable. When a row is clicked, an ajax call is made which returns some data. Sometimes the ajax call takes a little time, depending on the amount of data being returned. It is all working fine.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>The problem occurs when the rows are clicked quickly, one after the other. In short, before the previous ajax call returns, if the row is clicked (i.e. a new ajax call is made), I get an error. </p>
  
  <pre><code>Uncaught TypeError: Property 'callback' of object [object Window] is not a function 
  </code></pre>
  
  <p>(The ajax call returns a JSONP data)</p>
  
  <p>It looks like somehow the ajax calls are getting mingled (?), but I am not sure of this. Can anyone please tell me why does this happen?</p>
  
  <p>Please let me know if any more information is required to clarify the issue.</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Here is some ajax code:</p>
  
  <pre><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,
                          .
                          .
                          .
                      }
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>Here is the class which is assigning the <code>callback</code> its name. If the default callback is null, then it assigns a default value, "callback". But looks like somehow the default callback is always null and hence it always assigns "callback".</p>
  
  <pre><code>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);
          }
      }
  }
  </code></pre>
  
  <p>And the above class is being referenced in <code>mvc-servlet.xml</code> as follows:</p>
  
  <pre><code>    &lt;mvc:message-converters&gt;
          &lt;bean
              class="citygrid.feedmanager.web.converter.MappingJacksonJsonpConverter"&gt;
              &lt;property name="supportedMediaTypes"&gt;
                  &lt;list&gt;
                      &lt;value&gt;application/x-javascript&lt;/value&gt;
                  &lt;/list&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
      &lt;/mvc:message-converters&gt;
  </code></pre>