Jump to content

updating php


ngreenwood6

Recommended Posts

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

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

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

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

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.