English 中文(简体)
在按顺序推迟一段时间后,将存放在垃圾箱中
原标题:execute php file in jquery after a time delay in sequence

i) 具备一种分类功能,即需要以下列方式开展工作:

1. call a php file
2. log the values return by php file
3. have time delay
      again repeat the above process for number of time

为此而撰写的书目和网址文件

<script type="text/javascript">
$(document).ready(function() {
listsValues="1,10,20";
n=0;
msgids = listsValues.split( , );
$.each(msgids, function() {
html="TEST MESSAGE";
 n++;
setTimeout(function() {
$.ajax({
                type: "POST",
                url: "test1.php",
                cache:false,
                data:"id="+ msgids[n],
                dataType: json ,
                success: function(json)
                {
                var foo = json.foo;
                uemail = foo.split( , );
                console.log(uemail)
                }
            });
 }, 1000);

 });

  });
</script> 

页: 1

<?php
$id=$_POST[ id ];

$val="";
for($i=1;$i<=$id;$i++) { 

$val.=$i;

}

$return["foo"] =$val;

print stripslashes(json_encode($return));

?>

but this is not working as a way i want, when i execute this script i can see in firebug test1.php file executes (called) for 3times and after that values are written in console

as i said waht i want was
1. execute test1.php file
2. write value in console
3. give delay

then repeat

增 编

最佳回答

我认为你正在寻找这样的东西:

<script type="text/javascript">
function request(n) {
    $.ajax({
        type: "POST",
        url: "test1.php",
        cache:false,
        data:"id="+ msgids[n],
        dataType: json ,
        success: function(json)
        {
            var foo = json.foo;
            var uemail = foo.split( , );
            console.log(uemail);
            setTimeout(
                function() { 
                    request(n);
                }
                , 1000
            );
        }
    });
}

$(document).ready(function() {
    var listsValues="1,10,20";
    var n=0;
    var msgids = listsValues.split( , );
    $.each(msgids, function() {
        var html="TEST MESSAGE";
        n++;
        request(n);
    });
});
</script>
问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签