title: json(p), solr, jquery 1.5.2, 'not called'?
body: <p>I have an instance of a snapshot of Apache Solr 4.0 running. Solr, for any who do not know, provides an HTTP endpoint that performs queries. You can ask it to return results as json or jsonp (or other things that aren't relevant).</p>
  
  <p>Using jquery 1.5.2, I tried to use <code>$.ajax</code> to talk to this, using code from the ajax-solr project on github. The author thereof set things up for jsonp to allow things to work cross-domain.</p>
  
  <p>When you ask solr for jsonp, it really does jsonp. It does wrap the json in the function call.</p>
  
  <p>In that (jsonp) mode of operation, I could not get it to work with either Chrome or Firefox 4. I did some debugging into jquery, but I may have followed a trail of red herrings. </p>
  
  <p>The triggering problem seemed to be that solr returns a content type of 'text' instead of 'application/json'. This, in turn, triggers some complex code in jquery that tries multiple conversion strategies.</p>
  
  <p>In Chrome, the ILLEGAL SYNTAX throw seems to occur when the whole lump is appended to a DOM script node. In Firefox, there's no obvious error, but the jsonp function never gets called.</p>
  
  <p>When I change things to use plain json instead of jsonp, it all works fine (I have solr running in the same host:port as the static content that talks to it.)</p>
  
  <p>I've pasted the giant lump of jsonp and linked it below. It's syntactically valid. Mystified, I am, but not stuck, since, for my application, using plain json works fine.</p>
  
  <p>Answerers point out that the text included chars that are invalid in jsonp because they are invalid in javascript as an explanation for the jsonp failure.</p>
  
  <p>Code to talk to solr:</p>
  
  <pre><code>var url = this.solrUrl + servlet + '?' + this.store.string() + '&amp;wt=json&amp;json.wrf=?';
  jQuery.ajax({
            url: url,
            dataType: 'jsonp',
            success: function (data, textStatus, xhr) { 
                  self.handleResponse(data); 
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert(textStatus + " " + errorThrown);
            }
          });
  </code></pre>
  
  <p>This comes to the error function with errorThrown:</p>
  
  <p>errorThrown: "jQuery15205321112349629402_1304645690480 was not called"</p>
  
  <p>The response looks like a function call to that lovely item.</p>
  
  <p>The Chrome console says, 'Uncaught SyntaxError: Unexpected token ILLEGAL'.</p>
  
  <p>I captured the full load of javascript, and fed it to jsLint, which has no complaints.</p>
  
  <p>Pastebin: <a href="http://pastebin.com/ft5rw6uT" rel="nofollow">http://pastebin.com/ft5rw6uT</a></p>
  
  <p>I'm going to try to go catch the parsing exception in chrome.</p>
  
  <p>Here's where jquery get the throw:</p>
  
  <pre><code>     // Evalulates a script in a global context
      globalEval: function( data ) {
      if ( data &amp;&amp; rnotwhite.test(data) ) {
          // Inspired by code by Andrea Giammarchi
          // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
          var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement,
              script = document.createElement( "script" );
  
          if ( jQuery.support.scriptEval() ) {
              script.appendChild( document.createTextNode( data ) );
          } else {
              script.text = data;
          }
  
          // Use insertBefore instead of appendChild to circumvent an IE6 bug.
          // This arises when a base node is used (#2709).
          head.insertBefore( script, head.firstChild );
          //Chrome annotates the above with:
          //jquery-1.5.2.js:593Uncaught SyntaxError: Unexpected token ILLEGAL
          head.removeChild( script );
      }
  }
  </code></pre>
  
  <p>And here's a version acquired with CURL, using a shorter string for the function name.</p>
  
  <p><a href="http://pastebin.com/zB6BkmEL" rel="nofollow">http://pastebin.com/zB6BkmEL</a></p>