title: ajax to post and return html to display in div
body: <p>jQuery v 1.9.0</p>
  
  <p>When the page loads I am firing two functions (get_month() &amp; get_todays_events()) and those return the calendar and today's events html.</p>
  
  <p>Sometimes when I refresh the page, it will display the today's events twice and does not display the calendar(month), as seen below.</p>
  
  <p><img src="https://i.stack.imgur.com/bCane.png" alt="enter image description here">
  <strong>Half the time it works just fine, as seen below:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/NftPQ.png" alt="enter image description here"></p>
  
  <p>There are no errors in the firebug console. It works fine as a stand-alone app, but when I incorporate it into Jasig's uPortal, it messes up.</p>
  
  <p>Then I tried stripping the html that gets sent back from the ajax posts and I noticed the get_todays_events(); may be the culprit, but I still don't know what it could be.</p>
  
  <p>Is there something in the html that may be tripping things up or should I have a delay on firing that function after the get_month(); fires?</p>
  
  <pre><code>$.noConflict();
  jQuery(document).ready(function($) {
  
    function get_month()
    {
      var url_month = jQuery("#days_for_month_url").attr("href");
  
      var form_data = { ajax : '1' };
  
      jQuery.ajax({
        type: "POST",
        dataType: "html",
        url: url_month,
        crossDomain: true,
        data: form_data,
        success: function( default_month_msg ) {
  
          jQuery('#display-month').html(default_month_msg);
  
        } // end success
  
      }); // end ajax
      //return false;
    }
  
    function get_todays_events()
    {
      var url_todays_events = jQuery("#todays_events_url").attr("href");
  
      var form_data = { ajax : '1' };
  
      jQuery.ajax({
        type: "POST",
        dataType: "html",
        url: url_todays_events,
        crossDomain: true,
        data: form_data,
        success: function( default_month_msg ) {
  
          jQuery('#display_todays_events').html(default_month_msg);
  
        } // end success
  
      }); // end ajax
      //return false;
    }
  
    get_month();
    console.log("display calendar");
  
    get_todays_events();
    console.log("display today's events");
  
    jQuery(document).on('click', "a.view_events", function(e) {
      e.preventDefault();
      var date = jQuery(this).data('date');
  
      // change if URL changes
      var url_events = jQuery("#events_for_day_url").attr("href");
  
      var form_data = {
        year : jQuery(this).data('year'),
        month : jQuery(this).data('month'),
        day : jQuery(this).data('day'),
        date : jQuery(this).data('date'),
        ajax : '1'
      };
  
      jQuery.ajax({
        type: 'POST',
        dataType: 'html',
        url: url_events,
        data: form_data,
        success: function( msg ) {
  
          jQuery('#display-events').html(msg);
          jQuery('#display-event_detail').html('');
          jQuery('#display_todays_events').html('');
  
        } // end success
  
      }); // end ajax
  
      return false;
  
    }); // end on.click view-events
  
    jQuery(document).on('click', "a.view_event_details", function(e) {
      e.preventDefault();
      var url_event_detail = jQuery("#event_detail_url").attr("href");
  
      var form_data = {
        event_id : jQuery(this).data('event_id'),
        ajax : '1'
      };
  
      jQuery.ajax({
        type: 'POST',
        dataType: 'html',
        url: url_event_detail,
        data: form_data,
        success: function( msg ) {
  
          jQuery('#display-event_detail').html(msg);
          jQuery('#display-events').html('');
          jQuery('#display_todays_events').html('');
  
        } // end success
  
      }); // end ajax
  
      return false;
  
    }); // end on.click view_event_details
  
    jQuery(document).on('click', "a.month_link", function(e) {
      e.preventDefault();
  
      jQuery('#display-events').html('');
  
      var url_days_for_month = jQuery("#days_for_month_url").attr("href");
  
      var form_data = {
        month_url : jQuery(this).data('month_url'),
        ajax : '1'
      };
  
      jQuery.ajax({
        type: 'POST',
        dataType: 'html',
        url: url_days_for_month,
        data: form_data,
        success: function( msg ) {
  
          jQuery('#display-month').html(msg);
          jQuery('#display_todays_events').html('');
  
        } // end success
  
      }); // end ajax
  
      return false;
  
    }); // end on.click view-month
  
    jQuery(document).on('click', "a.view_subscriptions", function(e) {
      e.preventDefault();
      var url_subscription = jQuery("#subscriptions_url").attr("href");
  
      var form_data = {
        ajax : '1'
      };
  
      jQuery.ajax({
        type: 'POST',
        dataType: 'html',
        url: url_subscription,
        data: form_data,
        success: function( msg ) {
  
          jQuery('#display-subscriptions').html(msg);
          //jQuery('#display-subscriptions').toggle();
  
        } // end success
  
      }); // end ajax
  
      return false;
  
    }); // end on.click view-subscriptions
  
    jQuery(document).on('click', "#update_subscriptions", function(e) {
      e.preventDefault();
      var url_update_subscription = jQuery("#update_subscriptions_url").attr("href");
  
      var vals = []
      jQuery('input:checkbox[name="calendar[]"]').each(function() {
          if (this.checked) {
              vals.push(this.value);
          }
      });
  
      var form_data = {
        ajax : '1',
        calendar: vals,
      };
  
      jQuery.ajax({
        type: 'POST',
        dataType: 'html',
        url: url_update_subscription,
        data: form_data,
        success: function( msg ) {
  
          get_month();
          jQuery('#display-subscriptions-update').html(msg).fadeOut(6000);
          jQuery('#display-subscriptions').html('');
          jQuery('#display-events').html('');
          jQuery('#display_todays_events').html('');
  
        } // end success
  
      }); // end ajax
  
      return false;
  
    }); // end on.click view-subscriptions
  
  }); // end document ready
  </code></pre>
  
  <p>Here is the html that is returned on success for the get_todays_events() function</p>
  
  <pre><code>&lt;h3&gt;Today's Events&lt;/h3&gt;
  
  
    &lt;p&gt;&lt;a href="#" class="view_event_details" data-event_id="68"&gt;All About Heroin&lt;/a&gt; - 12:30 pm&lt;/p&gt;
  
  
    &lt;p&gt;&lt;a href="#" class="view_event_details" data-event_id="67"&gt;African Storyteller - Ekow King&lt;/a&gt; - 12:30 pm&lt;/p&gt;
  
  
    &lt;p&gt;&lt;a href="#" class="view_event_details" data-event_id="66"&gt;Men&amp;rsquo;s Basketball vs. Columbia-Greene Community College&lt;/a&gt; - 6:00 pm&lt;/p&gt;
  </code></pre>
  
  <p>UPDATE: checked the net tab in firebug and examined XHR, when using in uPortal, it would fire off two post requests and two get requests. Both POST requests were retuning 0 byte, but the GET requests were returning something. I changed them to GETS, since I wasn't really asking the user to enter data, but click a link that had the data already (that being the date they wanted view events for), so I appended the date value to the URL I was passing into the ajax get request, then it returned it correctly every time.</p>