Reputation: 488
My problem is that my code is really long and complicated, because it's normal xmlhttp and I want to switch it over to jQuery. I'm pretty sure there's shorthand functions for it? This is my current code:
function getContent() {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
replace_page = xmlhttp.responseText;
doc.getElementById("content").innerHTML = replace_page;
$("#content").children().hide();
$("#content").children().fadeIn("slow");
//do some other stuff
}
navigating = false;
};
xmlhttp.open("GET",site_location+"/pages/"+page+".php",true);
xmlhttp.send();
}
I found this example, and this works perfectly, but I'm also going to have to use this for forms...
Is there a simple way I can change it? I know it'll probably involve the serialising function, right?
Upvotes: 0
Views: 48
Reputation: 388316
look at $.ajax();
$.ajax({
type: 'GET',
url: site_location+"/pages/"+page+".php",
}).done(function(html){
$('#content').html(html).children().hide().fadeIn("slow");
})
or better using load() since the objective is to load a html content to a target element
$('#content').load(site_location+"/pages/"+page+".php", function(){
$(this).children().hide().fadeIn("slow");
})
Upvotes: 2