title: JQuery and Ajax: Cannot read property 'length' of undefined
body: <p>I am trying to get a particular request from website by using variable in the URL and AJAX to display JSON. It seems like everything is working but there is an error "TypeError: Cannot read property 'length' of undefined". A debugger points to JQuery file and the line in my script ($.ajax.success).</p>
  
  <pre><code>function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&amp;");
    for (var i = 0; i &lt; vars.length; i++) {
      var pair = vars[i].split("=");
      if (pair[0] == variable) {
        return pair[1];
      }
    }
    alert('Query Variable ' + variable + ' not found');
  }
  
  $(document).ready(function () {
  
    var output = $('#news');
    var postid = getQueryVariable('id');
  
    $.ajax({
      url: 'http://www.domain.pro/api/get_post/?post_id=' + postid + '&amp;post_type=news',
      async: false,
      callback: 'callback',
      crossDomain: true,
      contentType: 'application/json; charset=utf-8',
      type: 'POST',
      dataType: 'jsonp',
      timeout: 5000,
      success: function (data, status) {
         $.each(data.posts, function (i, item) {
          var news = '&lt;div&gt;' + item.title + '&lt;/div&gt;&lt;div&gt;' + item.content + '&lt;/div&gt;&lt;hr/&gt;';
  
          output.append(news);
  
  
        });
      },
      error: function () {
        output.text('There was an error loading the data.');
      }
    });
  })
  </code></pre>
  
  <p>Could you please help me to sort this out? Really appreciate your halp.</p>