|
 |
|
[สอบถาม] การส่งตัวแปร PHP ไปเช็คเงื่อนไข (if else) ใน JS ajaxForm |
|
 |
|
|
 |
 |
|
สอบถามการส่งตัวแปร PHP ไปเช็คเงื่อนไข (if else) ใน JS
คืออยากให้มีการแจ้งเตือน (alert) หากตรวจสอบว่า CODE ไม่ถูกต้อง ก่อนเข้าคำสั่ง ajaxForm
หากไม่มีการส่งตัวแปร $error มาก็ให้ทำงานปกติ
Code (PHP)
if(empty($_SESSION['code'] ) || strcasecmp($_SESSION['code'], $_POST['code']) != 0)
{
$errors = "CODE ERROR";
}
if(empty($errors))
{
//INSERT + UPLOAD
}
ตามโค๊ดด้านล่างนี้จะเขียนเพิ่มได้ยังงัยครับ
Code (JavaScript)
(function() {
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
//console.log(percentVal, position, total);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
}
});
})();
ขอบคุณครับ 
โค๊ดอ้างอิง
http://malsup.com/jquery/form/progress2.html
Tag : PHP, MySQL, JavaScript, jQuery

|
|
 |
 |
 |
 |
Date :
2014-02-20 14:31:39 |
By :
imagineverend |
View :
1232 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
(function() {
<?php if(!isset($errors) || $errors != "CODE ERROR"){ ?>
var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');
$('form').ajaxForm({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
//console.log(percentVal, position, total);
},
success: function() {
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
},
complete: function(xhr) {
status.html(xhr.responseText);
}
});
<?php } ?>
})();
|
 |
 |
 |
 |
Date :
2014-02-20 15:36:27 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|