Q:

Ajax get php data every x second with function

setInterval(function(){
    $.get('ajax.php', function(data) {
        $('.result').html(data);
    });
}, 5000);

I found this code. But this is not enough for me.. I want this like this. I dont know javascript. I could have some mistake.. I writing this to make you understand.
function getdata(getdatafrom, resultclass){
    $.get('getdatafrom', function(data) {
        $('resultclass').html(data);
    });
}

When I use it:
setInterval(getdata('get.php?action=test','.resultclass'), 5000);

I ll use this scipt.
I want to use code like this, cause I ll get a lot of stuff and I want to run at one code for develop eaisly.

A:

Your code should be as following :
function getdata(getdatafrom, resultclass){
    $.get(getdatafrom, function(data) {
        $(resultclass).html(data);
    });
}

By removing the single quote ' arround the variables it should works fine.
function getdata(getdatafrom, resultclass){
    $.get('getdatafrom', function(data) {
__________^___________^
        $('resultclass').html(data);
__________^___________^
    });
}

When you're using the single quotes ' the variables (getdatafrom and resultclass) considered as strings.
If you don't want to wait 5 seconds for the first time you could call getdata  by adding the following line just before setInterval() :
getdata('get.php?action=test','.resultclass')

Hope this helps.

