2010-03-02 136 views
1

从jQuery的调用PHP文件我有以下的jQuery中的变量在特定的时间间隔

var uemail="[email protected],[email protected],[email protected]"; 
var subj="test message"; 
var text="<b>This is Email Body Text</b>"; 

我有一个PHP文件名为“email.php”发送电子邮件

<?php 

     $email =$_GET['email']; 
     $subject =$_GET['subj']; 
     $message = $_GET['text'];; 

    if(mail($email, $subject, $message, "From: $email")) 
    echo "1"; 
    else 
    echo "0"; 
?> 

我想要做的是

呼叫email.php我在变量uemail中有电子邮件地址的次数,每次将电子邮件,子邮件,文本传递给email.php并在10秒间隔内打印结果每次之间email.php c alled。

[email protected](OK)
[email protected](错误)
[email protected](OK)

感谢

+2

你的问题是什么? – Natrium 2010-03-02 12:53:41

+0

@Natrium - 你对这个问题有什么不了解? – user113716 2010-03-02 13:10:23

回答

1

如果您不希望多个定时器并行运行,则可以使用其他方法。

var uemail="[email protected],[email protected],[email protected]"; 

    uemail = uemail.split(','); 

    var interval; 
    var counter = 0; 
    var check = function() { 
          if(counter < uemail.length) { 
           // Send email post 
           counter++; 
          } else { 
           clearInterval(interval); 
          } 
       }; 

    interval = setInterval(check,10000); 
2

我想你想一个在你的javascript这样的线: setInterval(function() {$.ajax{url:'url of emails.php'};}, 10000);

这将使每一10000毫秒的PHP页面的ajax请求。

4
var n = 1; 
$.each(uemail.split(','), function() { 
    var data = {email: this.valueOf(), subj: subj, text: text}; 

    setTimeout(function() { 
     $.post('http://.../email.php', data, function(resp) { 
      alert(data.email + (resp ? 'ok' : 'error')); 
     }); 
    }, n++ * 10000); 
}); 

这样你就不必在意停止间隔。