Jump to content

How to refresh SRC in iframe with AJAX?


spaceman12

Recommended Posts

Please help to refresh the src=' ' in within the iframe tag.

 

the code I used is

<script type='text/javascript'>
var xmlhttp;
function callAjax()
{
var str=document.getElementById('chat').value;
if(window.XMLHttpRequest)
{
	xmlhttp=new XMLHttpRequest();
}
else
{
	xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
}
xmlhttp.onreadystatechange=function()
{
	if(xmlhttp.readyState==4 && xmlhttp.status==200)
	{
		document.getElementById('iframe_chat').innerHTML=xmlhttp.responseText;
	}
}
xmlhttp.open('post', 'forum_chat.php', true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send('chat='+str);	

}

</script>

 

 

All is working fine except the SRC dont refresh each time the ajax function is called unless i refresh the whole page  to view the updates result.

thank you

Link to comment
https://forums.phpfreaks.com/topic/225235-how-to-refresh-src-in-iframe-with-ajax/
Share on other sites

Have you considered http://www.prototypejs.org/api/ajax/updater

callAjax = function ()
{
               	new Ajax.Updater('iframe_chat', 'forum_chat.php',
		{
		parameters: {ID: $F('chat')},
		onFailure: function(){alert('Error.');}
		});
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.