AV1611 Posted October 6, 2008 Share Posted October 6, 2008 Hi, I wrote a shoutbox in PHP. It works very well except one problem: The box is a div that shows the posts and a textarea at the bottom. the whole thing uses a meta refresh at 30 seconds... Now, the problem is if you are typing in the box, it will refresh, and that's annoying cause you never really have enough time to finish your shout it seems like... So, keep in mind I know ZERO js or ajax, only PHP... The top DIV content comes from mysql and has a ton of filters for smileys, bad words, bbcode, etc... already in it... I would like the top div to refresh independently of the bottom... sure, I could put the top in an iframe... and put the meta refresh in there, but and iframe in and iframe(the shoutbox is part of a bigger page) that just seems kinda lame. Can someone help? Quote Link to comment https://forums.phpfreaks.com/topic/127290-dont-know-if-ajax-is-the-answer/ Share on other sites More sharing options...
exally Posted October 7, 2008 Share Posted October 7, 2008 don't use meta refresh, use the setInterval or setTimeout function in javascript, and when the focus is on the shoutbox i tihink you use clearTimeout.. below is two lines that i have used in the past. Hope it helps. alertTimerId = setTimeout(sendRequest2('ajaxhottime',0), 30000); clearTimeout(alertTimerId); Quote Link to comment https://forums.phpfreaks.com/topic/127290-dont-know-if-ajax-is-the-answer/#findComment-658653 Share on other sites More sharing options...
AV1611 Posted October 7, 2008 Author Share Posted October 7, 2008 Thank you and I will try and implement what you suggest... Please note however I know ZERO js. None. Nada. I know PHP/HTML/CSS. I just have to do a client side not server side for this problem is the only reason I'm looking at js or ajax hints welcome! Quote Link to comment https://forums.phpfreaks.com/topic/127290-dont-know-if-ajax-is-the-answer/#findComment-659203 Share on other sites More sharing options...
AV1611 Posted October 7, 2008 Author Share Posted October 7, 2008 I give up. The text is generated via a php script. how do I do the refresh on the DIV ? Quote Link to comment https://forums.phpfreaks.com/topic/127290-dont-know-if-ajax-is-the-answer/#findComment-659386 Share on other sites More sharing options...
exally Posted October 8, 2008 Share Posted October 8, 2008 look at the prototype ajax work. http://prototypejs.org/learn/introduction-to-ajax function sendRequest2(divframe, idx) { glbVar2 = divframe; clearTimeout(alertTimerId); new Ajax.Request("includes/ajax_alt.php?mode=stop&id="+idx, { method: 'post', onComplete: showResponse2 }); return false; } function showResponse2(req) { clearTimeout(alertTimerId); document.getElementById(glbVar2).innerHTML= req.responseText; clearTimeout(alertTimerId); alertTimerId = setTimeout(sendRequest2('ajaxhottime',0), 30000); } with one of my real life work. divframe is the Id of your div. The ajax_alt.php file is one that your have to create and call your php in that. In this case i am posting 2 get values in order for me easily use ajax without creating 100 dfifferent php files. but you should be able to do something good. note, do note return a php value it won't work. print or echo everything in your PHP file. Quote Link to comment https://forums.phpfreaks.com/topic/127290-dont-know-if-ajax-is-the-answer/#findComment-659545 Share on other sites More sharing options...
AV1611 Posted October 20, 2008 Author Share Posted October 20, 2008 Thank you so very much. I feel impotent. I just have no idea what to do with the code sample you provided. I don't even know JS just php. Unless a kind person wants to help me understand how to implement the answer I'll have to go away... sigh... Quote Link to comment https://forums.phpfreaks.com/topic/127290-dont-know-if-ajax-is-the-answer/#findComment-670204 Share on other sites More sharing options...
Maq Posted October 20, 2008 Share Posted October 20, 2008 I feel impotent. sorry to hear that Quote Link to comment https://forums.phpfreaks.com/topic/127290-dont-know-if-ajax-is-the-answer/#findComment-670213 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.