title: Use of success / jsonpCallback with ajax request
body: <p>I'm developing an application for Netflix using their OData API. I've followed <a href="http://stephenwalther.com/blog/archive/2010/04/01/netflix-jquery-jsonp-and-odata.aspx" rel="nofollow noreferrer">Stephen Walther's blog entry</a> on how to query the OData API. In it, he uses the following code:</p>
  
  <pre><code>$.ajax({
     dataType: "jsonp",
     url: query,
     jsonpCallback: "callback",
     success: callback
  }); 
  </code></pre>
  
  <p>In my application, I need to use the OData's paging links, to retrieve the full listings. My code is as follows:</p>
  
  <pre><code>// create url and handle ajax call to Netflix
    function getTitles() {
      query = "http://odata.netflix.com/v2/Catalog" // netflix odata base url
      + "/Genres('Television')" // select Genre
      + "/Titles" // top-level resource
      + "?$select=NetflixApiId,Name,BoxArt,Synopsis,ReleaseYear,AverageRating,Series" // choose fields 
      + "&amp;$orderby=Name" // Sort results by name
      + "&amp;$filter=Instant/Available eq true"  // filter by instant view
      + " and Type eq 'Season'" // select only seasons
      + "&amp;$expand=Series" // include series data
      + "&amp;$callback=callback" // specify name of callback function
      + "&amp;$format=json"; // json request
      $.ajax({
        dataType: "jsonp",
        url: query,
        jsonpCallback: "callback",
        success: callback,
        error: function(XHR, textStatus, errorThrown){
          alert(textStatus + ":" + errorThrown);
        } 
      });
    }
  
  // create seasons array and and repeat ajax call until all results are returned 
    function callback(result) {
      seasons = seasons.concat(result["d"]["results"]);
      if (typeof result["d"]["__next"] != 'undefined') {
        var urlJSONP = result["d"]["__next"] + "&amp;$callback=callback&amp;$format=json";
        $.ajax({
          dataType: "jsonp",
          url: urlJSONP,
          jsonpCallback: "callback",
          success: callback,
          error: function(XHR, textStatus, errorThrown){
            alert(textStatus + ":" + errorThrown);
          } 
        });
      } else {
        processResults();
      }
    }
  </code></pre>
  
  <p>However, when this runs I keep getting a <code>parserError</code>. It appears that the callback function is being called twice. If I remove the <code>success: callback</code> line, the application works fine. My question is: Is there a problem with leaving the <code>success</code> line of code from the ajax call? Or why would it be necessary to include both the <code>jsonpCallback</code> and <code>success</code> lines? I'm mainly asking this out of curiosity, because the application seems to work fine without both callback lines.</p>