JSONP Cross Domain Error

JSONP Cross Domain Error

With some help from people in IRC chat and this forum, about two years ago I wrote some code to take data from an HTTPS site and then return it to my HTTP site.

Well long story short, IE sucks and has issues in version 8 & 9 with my code.

I will let you know that I do not know javascript or jquery that well.  I'm sorry if my code is horrible looking.

  1. <script type="text/javascript">
  2.       $(".div1").empty();  // Make sure my div is clear.  My cms will not allow me to have an empty item so I had to add a &nbsp to it.
  3.  
  4.       $.ajax({
  5.             dataType:  "jsonp",
  6.             url: "https://secure.mysite.com/api/calendar",
  7.             success: function(data) {
  8.                  
  9.                   var date_sort_asc = function(a, b) {
  10.                         return new Date(a.StartDate).getTime() - new Date(b.StartDate).getTime();
  11.                   }

  12.                   data.sort(date_sort_asc);
  13.                   var $holder = "";
  14.                   var date = new Date();
  15.                   var d = new Date();
  16.                   var month = d.getMonth()+1;
  17.                   var day = d.getDate();
  18.                   var current_date = d.getFullYear() + "-" + (month<10 ? '0' : '') + month + "-" + (day<10 ? '0' : '') + day;
  19.                   var count = 0;
  20.  
  21.                   var weekday = new Array(7);
  22.                   weekday[0] = "Sunday";
  23.                   weekday[1] = "Monday";
  24.                   weekday[2] = "Tuesday";
  25.                   weekday[3] = "Wednesday";
  26.                   weekday[4] = "Thursday";
  27.                   weekday[5] = "Friday";
  28.                   weekday[6] = "Saturday";
  29.  
  30.                   var month = new Array(12);
  31.                   month[0] = "January";
  32.                   month[1] = "February";
  33.                   month[2] = "March";
  34.                   month[3] = "April";
  35.                   month[4] = "May";
  36.                   month[5] = "June";
  37.                   month[6] = "July";
  38.                   month[7] = "August";
  39.                   month[8] = "September";
  40.                   month[9] = "October";
  41.                   month[10] = "November";
  42.                   month[11] = "December";

  43.                   $.each(data, function(index, calendar) {
  44.                         if(calendar.StartDate >= current_date && count < 6)
  45.                         {
  46.                               $holder = "<li><a href=" + calendar.URL + " target='_blank'><h6>" + calendar.Title + "</h6><span>" + month[event_date[1] - 1] + " " + event_date[2] + "," + event_Date[0] + "</span></a></li>";
  47.                               $(".div1").append($holder);
  48.                               $holder = "";
  49.                               count += 1;
  50.                         }
  51.                   });
  52.             }
  53.       });
  54. </script>