i have following variables in jquery
var uemail="abc@domain.com,xyz@domain.com,gty@domain.com";
var subj="test message";
var text="<b>This is Email Body Text</b>";
i have one PHP file named "email.php" to send email
<?php
$email =$_GE开发者_开发问答T['email'];
$subject =$_GET['subj'];
$message = $_GET['text'];;
if(mail($email, $subject, $message, "From: $email"))
echo "1";
else
echo "0";
?>
what i want to do is
call email.php for number of time i have email address in variable uemail and each time pass email,subj,text to email.php and print result on page that with 10 Sec interval Between each time email.php called.
abc@domain.com (ok)
xyz@domain.com (Error) gty@domain.com (ok)
Thanks
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);
});
This way you won't have to take care about stopping the interval.
I think you want a line like this in your javascript:
setInterval(function() {$.ajax{url:'url of emails.php'};}, 10000);
That will make an ajax request to the php page every 10000 miliseconds.
Here's an alternate approach if you don't want multiple timers running parallel.
var uemail="abc@domain.com,xyz@domain.com,gty@domain.com";
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);
精彩评论