Yes, and I was thinking that. First of all I would recommend forgetting about Dynamic Ajax Content's loadobjs() function. From what I can tell you're not using it anyway. It has a few problems/limitations that aren't made clear on the demo page. If you need scripts or styles for your external pages, these should go on the outer page.
And this rootdomain variable isn't really needed. It was just a way of reminding/emphasizing that AJAX requests must be to the same domain as the page making them.
Now, for a simple loading of a page, or for one with only GET data, jQuery has a shorthand for its $.ajax() method called .load(). For:
Code:
ajaxpage(rootdomain+'/prices_2012.php?hid='+hid, 'pricearea')
you can do:
Code:
$('#pricearea').load('prices_2012.php', 'hid=' + hid);
And for:
Code:
ajaxpage(rootdomain+'/availability.php?hid='+hid, 'availabilityarea')
you can do:
Code:
$('#availabilityarea').load('availability.php', 'hid=' + hid);
jQuery also has a way of waiting until the browser is finished parsing the document before executing things, as well as a way to set some defaults for AJAX requests. So you could get rid of those two little scripts in the body and place this in the head after the external tag for jQuery:
Code:
<script type="text/javascript">
jQuery(function($){
$.ajaxSetup({cache: false, data: 'hid=colorado'});
$('#pricearea').load('prices_2012.php');
$('#availabilityarea').load('availability.php');
});
</script>
Further, since it appears there's only one form in the availabilityarea at a time and it appears there are only two possible identical forms and it appears they require the same onsubmit function, if all that's true, and since jQuery can assign events to elements which may not be there yet, we can skip the highlighted here:
Code:
<form action="#" onsubmit="$.ajax({url:'availability2.php', data: $(this).serialize(), cache: false, type: 'post', success: function(data){$('#availabilityarea').html(data);}});return false;">
on both availability.php and on availability2.php, and add to our code in the head:
Code:
<script type="text/javascript">
jQuery(function($){
$.ajaxSetup({cache: false, data: 'hid=colorado'});
$('#pricearea').load('prices_2012.php');
$('#availabilityarea').load('availability.php');
$('#availabilityarea form').live('submit', function(e){
e.preventDefault();
$.ajax({
url: 'availability2.php',
data: $(this).serialize(),
type: 'post',
success: function(data){$('#availabilityarea').html(data);}
});
});
});
</script>
Bookmarks