|
 |
|
onclick แล้วส่ง var php ไปที่ฟังก์ชั่น ยังไงอ่ะคะ ลองทำดูแล้วมันก็ไม่ไปอ่ะค่ะ ช่วยดูหน่อยค่ะว่าผิดตรงไหน |
|
 |
|
|
 |
 |
|
Code (PHP)
echo "<span id='mySpan'><input type=button value=send"?> onclick="computePrice(<? $buc_id ?>)";<? echo "> </span>"; // ทำปุ่มให้เมื่อคลิกแล้วจะส่ง $buc_id ไปที่ฟังก์ชั่นค่ะ เป็นฟังก์ชั่น ajax แล้วจะให้ส่งค่าที่ได้กลับมาแทนที่ปุ่ม เดิมค่ะ เลยเอา span ครอบไว้
Code (PHP)
function computePrice(str)
{
if (str=="")
{
document.getElementById("mySpan").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("mySpan").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","computeprice.php?buc_id="+str,true);
xmlhttp.send();
}
เป็นโค้ดเอแจ็กค่ะ
Code (PHP)
<?php
$buc_id=$_GET["buc_id"];
include('onlineshop.inc.php');
$sql="SELECT * FROM bucket_item WHERE Bucket_Id = '".$buc_id."'";
$result = mysql_query($sql);
echo "<table border='1'>";
while($row = mysql_fetch_array($result))
{
$PID = $row['Product_Id'];
$Pquan = $row['Quantity'];
echo "<tr> <td> $PID</td></tr>";
for($i=1; $i<=$Pquan; $i++)
{
echo "<tr> <td> $PID</td></tr>";
}
}
echo "</table>";
?>
เป็นโค้ดหน้า php ที่เอาไปหาค่าที่ต้องการมาใส่แทนที่ปุ่มค่ะ
คิดว่ามัน่าจะผิดที่การส่งค่า var php เข้า จาวาสคริปอ่ะค่ะ เพราะก่อนหน้านี้ใช้แบบเดียวกันนี้ส่งค่าthis.value ธรรมดามันก็ทำได้ค่ะ แต่พอมาทำเป็นส่งค่าด้วย var php ตอนนี้ค่าที่ได้แทนที่ปุ่มคือว่างๆอ่ะค่ะ
ช่วยดูให้หน่อยนะคะ ขอบคุณค่ะ
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax

|
|
 |
 |
 |
 |
Date :
2012-03-20 11:47:55 |
By :
gellarjung |
View :
1585 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
echo "<span id='mySpan'><input type=button value=send"?> onclick="computePrice(<? $buc_id ?>)";<? echo "> </span>"; // ทำปุ่มให้เมื่อคลิกแล้วจะส่ง $buc_id ไปที่ฟังก์ชั่นค่ะ เป็นฟังก์ชั่น ajax แล้วจะให้ส่งค่าที่ได้กลับมาแทนที่ปุ่ม เดิมค่ะ เลยเอา span ครอบไว้
computePrice(<? $buc_id ?>) น่าจะเป็น <?=$buc_id ?> หรือ <? echo $buc_id ?>
|
 |
 |
 |
 |
Date :
2012-03-20 12:06:49 |
By :
randOmizE |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง echo $buc_id ออกมาดูว่ามีค่าป่าว แล้วค่อย computePrice(<?=$buc_id ?>)
|
 |
 |
 |
 |
Date :
2012-03-20 12:53:09 |
By :
randOmizE |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|