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.
- <script type="text/javascript">
- $(".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   to it.
-
- $.ajax({
- dataType: "jsonp",
- url: "https://secure.mysite.com/api/calendar",
- success: function(data) {
-
- var date_sort_asc = function(a, b) {
- return new Date(a.StartDate).getTime() - new Date(b.StartDate).getTime();
- }
-
- data.sort(date_sort_asc);
- var $holder = "";
- var date = new Date();
- var d = new Date();
- var month = d.getMonth()+1;
- var day = d.getDate();
- var current_date = d.getFullYear() + "-" + (month<10 ? '0' : '') + month + "-" + (day<10 ? '0' : '') + day;
- var count = 0;
-
- var weekday = new Array(7);
- weekday[0] = "Sunday";
- weekday[1] = "Monday";
- weekday[2] = "Tuesday";
- weekday[3] = "Wednesday";
- weekday[4] = "Thursday";
- weekday[5] = "Friday";
- weekday[6] = "Saturday";
-
- var month = new Array(12);
- month[0] = "January";
- month[1] = "February";
- month[2] = "March";
- month[3] = "April";
- month[4] = "May";
- month[5] = "June";
- month[6] = "July";
- month[7] = "August";
- month[8] = "September";
- month[9] = "October";
- month[10] = "November";
- month[11] = "December";
-
- $.each(data, function(index, calendar) {
- if(calendar.StartDate >= current_date && count < 6)
- {
- $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>";
- $(".div1").append($holder);
- $holder = "";
- count += 1;
- }
- });
- }
- });
- </script>