Reputation: 19646
This is a question in response to thise: Javascript AJAX function not working in IE?
I need jQuery to do something like this:
function render_message(id)
{
var xmlHttp;
xmlHttp=new XMLHttpRequest();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById('message').innerHTML=xmlHttp.responseText;
document.getElementById('message').style.display='';
}
}
var url="include/javascript/message.php";
url=url+"?q="+id;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
Can someone write the function for me quickly?
Upvotes: 0
Views: 153
Reputation: 5243
Use JQuery's $.load() function (http://docs.jquery.com/Ajax/load):
$("#mydiv").load("a/url/here.html");
Upvotes: 0
Reputation: 488644
You can use the handy load()
function for this:
$('#message').load("include/javascript/message.php", {q: id}, function() {
$(this).show();
});
The callback function is assuming the message
div is hidden and you only want it show once the request is complete.
Upvotes: 5
Reputation: 83061
See $.ajax()
to retrieve pages and access the content. Documentation here.
Then use e.g. $("#yourElementId").html( myHtmlContent )
to replace the HTML. More doc here.
Upvotes: 1