Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Javascript (https://www.askmehelpdesk.com/forumdisplay.php?f=452)
-   -   passing variable to comet ajax function ,messaging system (https://www.askmehelpdesk.com/showthread.php?t=791841)

  • May 11, 2014, 06:17 PM
    dj_john
    passing variable to comet ajax function ,messaging system
    i am new at ajax and comet, and I'm trying to create messaging system here is the main page , and i have the user's id from the class (.h99) I'm passing it as (lon) to read.php then getting the file name from the database .
    everything is working fine ,but when i click on the user link nothing happening and the message box not refreshing to the new file name ,but it does after clicking and writing something, i need help to solve this problem .
    $(document).ready(function(){
    $('.friendclick').click(function(){
    dat2=$(this).data('frclick');
    $('.h99').val(dat2);
    comet(dat2);
    });
    });
    var timestamp = null; //read
    function comet(dat2) {
    $.ajax({
    type : 'Get',
    url : 'includes/read.php?timestamp=' + timestamp,
    async : true,
    cache : false,
    data: "lon="+dat2,
    success : function(data) {
    var json = eval('(' + data + ')');
    if(json['msg'] == ''){
    $('#msg').html('No msg');
    }else {
    $('#msg').html(json['msg']);
    $('#msg').animate({scrollTop: $('#msg').get(0).scrollHeight},200);
    }
    timestamp = json['timestamp'];
    setTimeout('comet(dat2)', 1000);
    },
    error : function(XMLHttpRequest, textstatus, error) {
    alert(error);
    setTimeout('comet(dat2)', 15000);
    }
    });
    }and here is the read.php , i get the ($file_name) from the DB$filename = 'messaging/'.$file_name.'.txt';
    $last = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;
    $current = filemtime($filename);
    while( $current <= $last) {
    usleep(100000);
    clearstatcache();
    $current = filemtime($filename);
    }
    $response = array();
    $response['msg'] = file_get_contents($filename);
    $response['timestamp'] = $current;
    echo json_encode($response);

  • All times are GMT -7. The time now is 05:31 AM.