how can we display a Ajax response to Iframe.for eg
i have some links in my page.when i click on each link i want to display some information in Iframe using ajax.
I am using prototype framework.I am getting the response from server.Now i just want to display this information to I frame. Is it possible?
if the iFrame has some kind of id to identify it, then you should be able to latch onto that element (document.getElementById(‘my iframe’).document) to get the iFrame’s document and tweak around with its elements.
var URL='http://localhost/index.php?id='+data;
var ajax = new Ajax.Request(URL,
{ method: 'get',onSuccess: function(display)
{
$('ifr').update(display.responseText);
} ,
onFailure: function(error)
{
alert('errors in js');
}
});
}
i am using proytotype for ajax.
here is my iframe code
<iframe width=“100%” name=“ifr” id=“ifr” src=“index.php” height=“700” frameborder=“0”></iframe>
So in your case, first off you’d need this handle little cross browser function to get the document of an iframe:
function getIframeDocument(element)
{
var doc = element.contentDocument;
if (doc == undefined || doc == null)
{
doc = element.contentWindow.document;
}
return doc;
}
Now that we’ve got that:
function ajax_aboutus_request(data)
{
var URL='http://localhost/index.php?id='+data;
var ajax = new Ajax.Request(URL,
{
method: 'get',onSuccess: function(display)
{
getIframeDocument($('ifr')).body.update(display.responseText);
} ,
onFailure: function(error)
{
alert('errors in js');
}