提问人:Sail Goyal 提问时间:6/3/2023 更新时间:6/3/2023 访问量:34
使用 AJAX 发送短信,CodeIgniter 中的进度条发送的实时短信总数
send sms using ajax with real time total sms sended by progress bar in codeigniter
问:
我使用 AJAX 发送短信,WAANT 显示 CodeIgniter 发送的短信总数的实时进度条
我想显示带有进度条的发送短信计数
我的控制器代码
$final_list = 'user list with data';
$recipients = count($final_list);
$sentCount = $totalsmsSend = $totalappSend = 0;
foreach ($final_list as $user_mail_key => $user_mail_value) {
$sentCount++;
if (in_array("sms", $sms_mail)) {
if ($user_mail_value['mobileno'] != "") {
$this->smsgateway->sendSMS($user_mail_value['mobileno'], $message, $template_id, "");
// $response['remainingSms'] = $recipients - ($sentCount);
$totalsmsSend ++;
}
}
if (in_array("push", $sms_mail)) {
if ($user_mail_value['app_key'] != "") {
$this->pushnotification->send($user_mail_value['app_key'], array(
'title' => $message_title, 'body' => $message
), "mail_sms");
// $response['remainingtoApp'] = $recipients - ($sentCount);
$totalappSend ++;
}
}
// $response['status'] = 'sending';
// $response['msg'] = 'Sending SMS ' . $sentCount . ' of ' . $recipients;
// $response['remaining'] = ($recipients - $sentCount);
// $response['progress'] = (($sentCount / $recipients) * 100);
//header('Content-Type: application/json');
// echo json_encode($response);
// ob_flush();
// flush();
// usleep(500000); // Delay for half a second (500ms) before sending the next SMS
}
$totalsend = array('sms' => $totalsmsSend, 'push' => $totalappSend);
echo json_encode(array('status' => 'success', 'api_res' => $totalsend, 'msg' => $this->lang->line('message_sent_successfully')));
和 Jquery ajax 代码
$("#group_form").submit(function (event) {
event.preventDefault();
var formData = new FormData();
var other_data = $(this).serializeArray();
$.each(other_data, function (key, input) {
formData.append(input.name, input.value);
});
var $form = $(this),
$this = $form.find(':submit');
var jqXHR = $.ajax({
type: "POST",
url: $form.attr('action'),
data: formData,
dataType: "JSON",
contentType: false,
processData: false,
cache: false,
beforeSend: function () {
$this.button('loading');
$('#smsprocess').modal({backdrop: 'static',keyboard: false,show: true});
},
success: function (data) {
if (data.status == 0) {
var message = "";
$.each(data.msg, function (index, value) {
message += value;
});
errorMsg(message);
} else{
$('#group_form')[0].reset();
successMsg(data.msg);
}
$('#smsprocess').modal('hide');
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.statusText == 'abort') {
errorMsg('Sending Process Aborted.');
return;
}
},
complete: function (data) {
$this.button('reset');
}
});
$('#abort').on('click', function() {
$('#smsprocess').modal('hide');
jqXHR.abort();
});
});
使用 AJAX 批量发送 1000+ 条短信,并在 CodeIgniter 中获取实时剩余的发送短信或发送的带有进度条的短信总数
答: 暂无答案
评论