Ask Experts Questions for FREE Help !
Ask
    dj_john's Avatar
    dj_john Posts: 1, Reputation: 1
    New Member
     
    #1

    May 11, 2014, 06:17 PM
    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);

Check out some similar questions!

Passing a Liver Function Test [ 4 Answers ]

Hi, I have to pass a liver function test in order to remain in good standing while on probation. I am 6'8", 270lbs, 25 years old and drink fairly heavily twice a week, abstaining the other five days. I work out a lot. My test is scheduled for 3 weeks from now. If I stop drinking now, will I...

Accessing home by passing alarm system [ 4 Answers ]

I have an alarm system in my home covers doors/windows, just breaking. I have recently had someone in my home. Couple small items were taken, just nuf to make you think they weren't missing but... I had keys missing and thought I lost them somewhere but they were lost on condo community property....

What are function of goods costing system? [ 0 Answers ]

What are function of goods costing system?

Costs of Bryant Evolution System w variable Heat Pump [ 3 Answers ]

What is the total buying with installation costs of a Bryant Evolution system with variable air handler with heat pump (15 SEER)? Thanks

Word Problem for 3 variable system of equations [ 4 Answers ]

Solve the system to find how many athletes finished in each place. Lawrence High prevailed in Saturdays track meet with the help of 20 individual-event placers earning a combined 68 points. A first place finish earns 5 points, a second place earns 3 points, and third place earns 1 point. ...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.