.getJSON() error when crlf doesn't match os's liking

.getJSON() error when crlf doesn't match os's liking

  1. function getRandomQuote() {
  2.        var quotes = [], randomIndex, quote;
  3.     $.getJSON('/quotes.json', function(data) { //http://api.jquery.com/jQuery.getJSON/
  4.         $.each(data, function(quote, cite) {
  5.             if ('' != quote && '' != cite) {
  6.                 quotes.push(quote + '|||' + cite);
  7.             }
  8.         });
  9.     })
  10.     .done(function() { console.log( "JSON success" ); })
  11.     .fail(function() { console.log( "JSON error" ); })
  12.     .always(function() { console.log( "JSON complete" ); });
  13.     //pick a random quote from the total number of quotes
  14.     randomIndex = parseInt(Math.random() * quotes.length);
  15.     //separate out quote and cite from array element
  16.     quote = quotes[randomIndex].split('|||'); //index 0 is "quote", index 1 is "cite"
  17.     document.getElementById('ip').innerHTML = quote[0];//"quote":
  18.     document.getElementById('icite').innerHTML = quote[1];//"cite":
  19.     return quote;
  20. }
  21. getRandomQuote();

this bug needs to be fixed so it works regardless of whether the file has lf or crlf for EOL or even a mixture. it's doable. I am using ff, but I could try testing with other browsers if need be.

also, I always get an error with this code, even with success, because randomIndex is always 0 and quotes.length is always 0. I have no idea what's going on behind the scenes now that I am getting
JSON success
JSON complete

I just know that for some reason, .each is not working.