|
 |
|
มีปัญหาไม่สามารถเลือก list menu แล้วอยากให้ดึงค่าของตัวแปรไปแสดงใน text box |
|
 |
|
|
 |
 |
|
คือ อยากให้ เลือก listmenu ประเภทน้ำมัน แล้วแสดงราคาน้ำมัน ลงใน text box
ถ้า ใช้แท็ก div เฉยๆ ก็สามารถแสดงราคาน้ำมันได้ (ที่คอมเม้นไว้อ่ะคะ)
แต่ถ้าลองเป็น text box มันไม่ขึ้นเลยค่ะ ไม่ทราบว่าผิดพลาดตรงไหน
ช่วยทีค่ะ ขอขอบคุณล่วงหน้านะคะ
showOilPrice.js
<script type="text/javascript">
function showOilPrice(str)
{
if (str=="")
{
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","callWebservice.php?q="+str,true);
xmlhttp.send();
}
</script>
currentOilPrice.php
<form name="currentOilPrice" method="post">
ประเภทน้ำมัน/แก๊สรถยนต์ :
<select id="product" name="product" onchange="showOilPrice(this.value);">
<option value="">เลือกประเภทน้ำมัน</option>
<option value="Blue Gasoline 91">Blue Gasoline 91</option>
<option value="Blue Diesel">Blue Diesel</option>
<option value="Blue Gasohol 91">Blue Gasohol 91</option>
<option value="Blue Gasohol E20">Blue Gasohol E20</option>
<option value="NGV">NGV</option>
<option value="Blue Gasohol 95">Blue Gasohol 95</option>
<option value="DIESEL PALM">DIESEL PALM</option>
<option value="Blue Diesel B5">Blue Diesel B5</option>
<option value="Blue Gasohol E85">Blue Gasohol E85</option>
</select>
ราคาน้ำมันลิตรละ : <input id="txtHint" value="" size="10" />
<!-- <div id="txtHint"></div> -->
</form>
<?
$q = $_GET["q"];
$client = new SoapClient("http://www.pttplc.com/pttinfo.asmx?wsdl");
$methodName = "CurrentOilPrice";
$param = array('Language' => 'EN');
$soapAction = "http://www.pttplc.com/ptt_webservice/CurrentOilPrice";
$objectResult = $client->__soapCall($methodName,array('parameters'=>$param),array('soapaction' => $soapAction));
//echo $objectResult->CurrentOilPriceResult;
$xmlstr = $objectResult->CurrentOilPriceResult;
$xml = simplexml_load_string($xmlstr);
$dom = new DOMDocument;
$dom->loadXML($xmlstr);
$x = $dom->getElementsByTagName('PRODUCT');
for($i=0;$i<=$x->length-1;$i++)
{
if($x->item($i)->nodeType==1)
{
if($x->item($i)->childNodes->item(0)->nodeValue == $q)
{
$y=($x->item($i)->parentNode);
}
}
}
$oilPrice = ($y->childNodes);
for($i=0;$i<$oilPrice->length;$i++)
{
if($oilPrice->item($i)->nodeType==1 && $oilPrice->item($i)->nodeName==PRICE)
{
//echo("<b>".$oilPrice->item($i)->nodeName.":</b>");
echo($oilPrice->item($i)->childNodes->item(0)->nodeValue);
}
}
?>
Tag : PHP, JavaScript, Ajax, WebService

|
|
 |
 |
 |
 |
Date :
2012-04-01 19:58:59 |
By :
CzPlussiiz |
View :
1214 |
Reply :
10 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผู้รู้ช่วยตอบทีนะคะ ยังทำไม่ได้เลย T^T
|
 |
 |
 |
 |
Date :
2012-04-02 21:05:46 |
By :
CzPlussiiz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
T^T ไม่มีใครรู้เลยหรอคะ ช่วยทีนะ
|
 |
 |
 |
 |
Date :
2012-04-06 14:14:11 |
By :
CzPlussiiz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
xmlhttp.responseText มันรีเทิร์นอะไรกลับมาบ้างครับ (ผมนึกว่ามันรีเทิร์นเฉพาะตัวเลขราคา)
|
ประวัติการแก้ไข 2012-04-06 15:24:32
 |
 |
 |
 |
Date :
2012-04-06 15:23:19 |
By :
ทองมี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง alert ดู มัน return โค้ดทั้งหน้าเลยค่ะ
|
 |
 |
 |
 |
Date :
2012-04-06 15:32:42 |
By :
CzPlussiiz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเอาโค้ดหน้า callWebservice.php มาดูหน่อยครับ
|
 |
 |
 |
 |
Date :
2012-04-06 15:58:01 |
By :
ทองมี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี่ค่ะ ช่วยดูให้ทีนะคะ
callWebservice.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Call CurrentOilPrice - PTT Web Service</title>
<script type="text/javascript">
function showOilPrice(str)
{
if (str=="")
{
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
//alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","callWebservice.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form name="currentOilPrice" method="post">
ประเภทน้ำมัน/แก๊สรถยนต์ :
<select id="product" name="product" onchange="showOilPrice(this.value);">
<option value="">เลือกประเภทน้ำมัน</option>
<option value="Blue Gasoline 91">Blue Gasoline 91</option>
<option value="Blue Diesel">Blue Diesel</option>
<option value="Blue Gasohol 91">Blue Gasohol 91</option>
<option value="Blue Gasohol E20">Blue Gasohol E20</option>
<option value="NGV">NGV</option>
<option value="Blue Gasohol 95">Blue Gasohol 95</option>
<option value="DIESEL PALM">DIESEL PALM</option>
<option value="Blue Diesel B5">Blue Diesel B5</option>
<option value="Blue Gasohol E85">Blue Gasohol E85</option>
</select>
ราคาน้ำมันลิตรละ : <input id="txtHint" value="" size="10" />
<!--<span id="txtHint"></span>-->
</form>
<?
$q = $_GET["q"];
$client = new SoapClient("http://www.pttplc.com/pttinfo.asmx?wsdl");
$methodName = "CurrentOilPrice";
$param = array('Language' => 'EN');
$soapAction = "http://www.pttplc.com/ptt_webservice/CurrentOilPrice";
$objectResult = $client->__soapCall($methodName,array('parameters'=>$param),array('soapaction' => $soapAction));
//echo $objectResult->CurrentOilPriceResult;
$xmlstr = $objectResult->CurrentOilPriceResult;
$xml = simplexml_load_string($xmlstr);
$dom = new DOMDocument;
$dom->loadXML($xmlstr);
$x = $dom->getElementsByTagName('PRODUCT');
for($i=0;$i<=$x->length-1;$i++)
{
if($x->item($i)->nodeType==1)
{
if($x->item($i)->childNodes->item(0)->nodeValue == $q)
{
$y=($x->item($i)->parentNode);
}
}
}
$oilPrice = ($y->childNodes);
for($i=0;$i<$oilPrice->length;$i++)
{
if($oilPrice->item($i)->nodeType==1 && $oilPrice->item($i)->nodeName==PRICE)
{
//echo("<b>".$oilPrice->item($i)->nodeName.":</b>");
echo($oilPrice->item($i)->childNodes->item(0)->nodeValue);
}
}
/*for($i=0;$i<$oilPrice->length;$i++)
{
if($oilPrice->item($i)->nodeType==1)
{
echo("<b>".$oilPrice->item($i)->nodeName.":</b>");
echo($oilPrice->item($i)->childNodes->item(0)->nodeValue);
echo("<br />");
}
}*/
//echo $xml;
/*foreach($xml->Table as $price){
echo "ราคาน้ำมัน".$price->PRICE;
echo "<br>";
}*/
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2012-04-06 16:01:44 |
By :
CzPlussiiz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือปกติ responseText มันจะคืนค่าข้อความในไฟล์นั้น ๆ ที่ถูกสั่งให้แสดง มาทั้งหมด ผมเลยคาดว่าน่าจะไม่ได้อ่าครับ (หรือไม่ลองตั้งหัวข้อใหม่ถามดูครับ เดี๋ยวพวกพี่วินน่าจะมาให้คำตอบที่ชัวร์ๆให้ได้)
|
 |
 |
 |
 |
Date :
2012-04-06 17:07:49 |
By :
ทองมี |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|