php - AJAX how to grab returning value AND database connections -


i quite new jquery , ajax. sending request via ajax check file 'test' every 5 seconds works fine. 'test' stands test.php file.

<script> $(document).ready(function () {     function load() {         var test = "<?php echo $test; ?>/";         $.ajax({ //create ajax request load_page.php             type: "get",             url: test,             datatype: "html", //expect html returned                 contenttype: "text/html",                         success: function (response) {                 $("#responsecontainer").html(response);                 settimeout(load, 5000)             }         });     }      load(); //if don't want click    // $("#display").click(load); //if want start display on click }); </script>  <div id="responsecontainer"></div> 

test.php

            $id = $this->session->userdata('userid');         $get_friends_notification = $this->friends_model->get_friends_alert_by_id($id);         if(isset($get_friends_notification) && !empty($get_friends_notification))         { ?>             <div id="test" style="width:200px; height:auto; border:1px solid red;">                 <h3>friend invitation from:</h3>         <?php                 foreach($get_friends_notification $key => $value)                 {                     $new_id =   $get_friends_notification[$key] = $value["frieinviter"];                     $new_name = $get_friends_notification[$key] = $value["username"];                      echo '<a href="'.base_url().'profile/get_user_data/'.$new_id.'">'.$new_name.'</a><br />';                 }         ?>             </div>     <?php         } 

then displays in div # responsecontainer works fine too.

$("#responsecontainer").html(response); 

in file 'test' checking database if there updates. pulling information db , return #responsecontainer. runs every 5 seconds, after ran first time grab last id pulled , before runs again , save in variable , pass id 'test' or process differently. want able use it. how can that??

example: ajax checks test.php file , find 5 rows. returns these 5 rows 5 ids. last id number 5. in meantime there other rows inserted next time find more rows. before checkes again want tell not check id 1,2,3,4,5 start id 6.

also how method works db connections? assuming have example 500 users, , on of theirs profiles check run every 5 seconds wouldnt kill database connections?

basically need add pgination effect in here. pass parameter in ajax request example : if getting 5 records @ time, initialize variable current_page = 0 , increment same request via ajax

    var current_page=0; function load() {     var test = "<?php echo $test; ?>/";     $.ajax({ //create ajax request load_page.php         type: "get",         url: test,         data : current_page         datatype: "html", //expect html returned             contenttype: "text/html",                     success: function (response) {             if(response.length!==0){                 $("#responsecontainer").html(response);                 current_page+=1;             }             settimeout(load, 5000)         }     }); } 

in php page make necessary changes (hope know how pagination done).


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -