ngreenwood6 Posted September 13, 2009 Share Posted September 13, 2009 I have a php function that I only want to run when the user clicks it. Basically, I have a chat bar that makes a query to the database. The problem is that the current situation is that whenever the user goes to a new page it is querying the database so as you can imagine it is taking up unnecessary bandwidth. The way this works is there is an icon in the chatbar that when clicked shows the results from the database in a pop window. But as it stands now it always makes the query but the user may never use it on the page if they dont want to see it. Because it makes this query the chatbar takes a couple of seconds to load. I would like to make it so that when the user clicks the icon the query is performed and the results are shown. The popup window is javascript because I do not want them to have to go to another page. Is this possible? Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/174054-updating-php/ Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 do you know ajax? Link to comment https://forums.phpfreaks.com/topic/174054-updating-php/#findComment-917467 Share on other sites More sharing options...
ngreenwood6 Posted September 13, 2009 Author Share Posted September 13, 2009 I do but it is kinda limited. Can I call a function through ajax? or how would i do it? Link to comment https://forums.phpfreaks.com/topic/174054-updating-php/#findComment-917470 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 yeah what i do is create an ajax.php page... so create an ajax request to that page and get the results you need. if you use jquery... ajax is so much easier you can google for some examples http://www.w3schools.com/PHP/php_ajax_database.asp Link to comment https://forums.phpfreaks.com/topic/174054-updating-php/#findComment-917481 Share on other sites More sharing options...
ngreenwood6 Posted September 13, 2009 Author Share Posted September 13, 2009 I actually am using jquery (alot of it). Can you provide me with a sample? Basically I have an image that the user clicks, then a window slides up(its just a div using jquery) and shows some messages. How would I make it populate that div with the info from the query? Link to comment https://forums.phpfreaks.com/topic/174054-updating-php/#findComment-917484 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 JS function getBookmarks(){ $.ajax({ type: "POST", url: "general_ajax.php", data: "request=getBookmarks", cache: false, success: function(html){ $('#bookmarks_body').html(html); $('#bookmarks_body').slideDown(); } }); } HTML <a href='javascript:getBookmarks();'>OPEN ME</a> <div style='display:none;' id='bookmarks_body'></div> PHP <?php switch($_POST['request']){ case 'getBookmarks': echo 'TEST'; break; } ?> Link to comment https://forums.phpfreaks.com/topic/174054-updating-php/#findComment-917488 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.