|
|
|
สอบถามวิธี update ตะกร้าสินค้า โดยกดปุ่ม Apply Code โดยไม่ต้องรีเฟรชหน้า |
|
|
|
|
|
|
|
ajax ครับ
|
|
|
|
|
Date :
2018-09-04 18:47:10 |
By :
menphurk |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ajax อีกเสียงครับ
|
|
|
|
|
Date :
2018-09-04 20:46:45 |
By :
Jatmentz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมลองใช้ ajax ครับ แต่ยังทำให้ ค่าของ discount ที่รับมาจาก ajax ไปคำนวน กับ $sum ใน php ไม่ได้ครับ
ผมเลยลองส่งค่าทั้ง code กับ $sum ไปใน ajax ด้วยเลย แต่ก็ยังไม่รู้วิธีรับค่ากลับมา 2 ตัวแปร
รบกวนด้วยนะครับ
ขอบคุณมากครับผม
Code (PHP)
<div class="col-xs-12">
<div class="col-xs-12">
<div class="totalbooking brown">
<?php
foreach ($_SESSION[room] as $key=>$val):
$_room = $db->GetRecord("room","roomtype='{$val[roomtype]}' AND ratecode='{$val[ratecode]}'");
$rate = $objRate->getRateByPeriod($period[idperiod],$_room[idroom]);
?>
<div class="col-xs-12"><strong class="strongbooking"><?=stripslashes($_room[roomname])?></strong></div>
<div class="col-xs-12">
<div class="col-xs-7"><p><?=$_SESSION[room][$_room[roomtype]][rooms]?> Room(s) x <?=$diffdate?> Night(s)</p></div>
<div class="col-xs-2"><p>THB</p></div>
<div class="col-xs-3 text-right"><p><?= number_format($_SESSION[room][$_room[roomtype]][rooms]*$diffdate*$rate[directbooking],2)?></p></div>
</div>
<div class="col-xs-12">
<div class="col-xs-7"><p>Extra Bed (<?=$_SESSION[room][$_room[roomtype]][extra]?> x <?= $rate[extrabed]?> x <?=$diffdate?>)</p></div>
<div class="col-xs-2"><p>THB</p></div>
<div class="col-xs-3 text-right"><p><?= number_format($_SESSION[room][$_room[roomtype]][extra]*$diffdate*$rate[extrabed],2)?></p></div>
</div>
<div class="col-xs-12">
<div class="col-xs-7">
<strong>Discount</strong>
</div>
<div class="col-xs-2">
<strong>THB</strong>
</div>
<div class="col-xs-3 text-right">
<strong id="discount">0</strong>
</div>
</div>
<div class="col-xs-12"><strong id="codestatus"></strong></div>
<?
$sum += ($_SESSION[room][$_room[roomtype]][rooms]*$diffdate*$rate[directbooking])+($_SESSION[room][$_room[roomtype]][extra]*$diffdate*$rate[extrabed]);
endforeach;
?>
<div class="col-xs-12">
<div class="col-xs-7"><h4>Total</h4></div>
<div class="col-xs-2"><h4>THB</hh45></div>
<div class="col-xs-3 text-right"><h4><?=number_format($sum,2);?></h4></div>
<input type="text" hidden value="<?=$sum?>" name="sum" id="sum">
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
Code (JavaScript)
var HttPRequest = false;
function doCallAjax() {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxDiscount.php';
var pmeters = "tcode=" + encodeURI( document.getElementById("code").value)+
"&tsum=" + encodeURI( document.getElementById("sum").value);
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function() {
if(HttPRequest.readyState == 3) { // Loading Request
document.getElementById("discount").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) { // Return Request
if(HttPRequest.responseText == '0') {
document.getElementById("discount").innerHTML = 0;
}
else {
document.getElementById("discount").innerHTML = HttPRequest.responseText;
}
}
}
}
Code (PHP)
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
session_start();
$strcode = trim($_POST["tcode"]);
$strsum = trim($_POST["tsum"]);
//*** Check Username ***//
$objConnect = mysql_connect("localhost","aaaaaa","aaaaaaa") or die("Error Connect to Database");
$objDB = mysql_select_db("aaaaaaaa");
//*** Check Username & Password ***//
$strSQL = "SELECT * FROM discount_code WHERE code = '".$strcode."' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
if(!$objResult){
//echo "<div class='col-xs-12'><strong>Sorry, this voucher is not valid.</strong></div>";
echo 0;
}else{
//*** Session ***//
if($objResult["dis"] != ''){
echo -($strsum*$objResult["dis"])/100;
}else{
echo -$objResult["price"];
}
session_write_close();
}
mysql_close($objConnect);
|
ประวัติการแก้ไข 2018-09-06 14:17:34 2018-09-06 14:49:21
|
|
|
|
Date :
2018-09-06 14:15:47 |
By :
insawasd |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
่jQuery + Ajax + Json นะครับ
|
|
|
|
|
Date :
2018-09-06 16:44:48 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|