[PHP] เขียน AJAX แล้วไม่สามารถรันบน google chrome ได้คะ รบกวนชี้แนะด้วยนะคะ

เริ่มโดย SG14, 15 มีนาคม 2012, 16:07:13

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

SG14

เขียน AJAX แล้วไม่สามารถรันบน google chrome ได้คะ

โปรแกรมโดยรวมคือ เช็ค radio box แล้วจะไปแสดงคำนวณค่าจัดส่งในหน้า ship_cal.php
และจะมีปุ่มหน้าถัดไปแสดงขึ้นมา
ลองเทสแล้ว google chrome ไม่สามารถแสดงปุ่มขึ้นมาได้เมื่อ check radio box คะ

โค๊ดมีดังนี้คะ

ส่วน head ที่ใส่โค๊ด ajax

   <script language="javascript">
function shipping(type) {
document.getElementById('shipping').innerHTML="";
var product;
            if (window.ActiveXObject) {
                product = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest) {
                product = new XMLHttpRequest();               
            }
product.onreadystatechange = function()
{
  if(product.readyState == 4) {
document.getElementById('shipping').innerHTML = product.responseText;   
    }
}
product.open("GET","ship_cal.php?ship_type=" type,true);
document.getElementById('next').innerHTML="<input type='submit' name='submit' id='submit' value='หน้าถัดไป' >";
product.send(null);
        }
function openfile(file){
window.location=file;
}
</script>



body

<?php 
include("../../include/connect.php");
$sql="select * from shipping";
$query=mysql_query($sql);
$num=mysql_num_rows($query);
for($i=0;$i<$num;$i  ){
$rs=mysql_fetch_array($query);
echo "<p><input type='radio' name='RadioGroup1' value='$rs[id_ship]' id='RadioGroup1_0' onfocus="shipping('$rs[id_ship]')" />$rs[type_ship]</p>";
}
?>

<p align="center">
        <div id="shipping" align="center"></div> //แสดงราคาค่าจัดส่ง
        </p>
          <form id="form1" name="tran" method="post" action="shipadd.php">
              <table width="100%" border="0" cellspacing="10" cellpadding="10">
                <tr>
                  <td align="center"><table width="260" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="60"><input type="button" name="button" id="button" value="ก่อนหน้า" onclick="openfile('basket.php')"></td>
                        <td width="100"><input type="button" name="button2" id="button2" value="เลือกสินค้าเพิ่ม" onclick="openfile('../../index.html')"></td>
                        <td width="100"><div id="next"></div></td> //แสดงปุ่ม
                      </tr>
                  </table></td>
                </tr>
              </table>
          </form>

bonshington

jquery ง่ายกว่าคับ ถ้าใช้ js แบบนี้ เด๋วก็จะเจอ chrome, ie, ff อีกมากมาย

ถ้าจำไม่ผิด chrome มันจะใช้ตัวแปรชื่อ xhr อะไรซักอย่าง

kuznetsova

document.getElementById('next').innerHTML="<input type='submit' name='submit' id='submit' value='หน้าถัดไป' >";

โค้ดส่วนนี้น่าจะไม่ทำงานใช่ไหมครับ ลองเปลี่ยนเป็น

  input = document.createElement("input");
  input.value = "หน้าถัดไป";
  input.id= "submit";
  input.name = "submit";

  document.getElementById('next').appendChild(input);

ใช้ appendChild แทนดูอะครับ
เว็บที่ทำจาก Blogger สวยงามได้แค่ไหนชม
[direct=https://www.forexfights.com]วิธีเทรดฟอเร็กซ์ กรอบเวลาต่างๆ[/direct]
[direct=https://babbaan.in]แบบบ้านความรู้เรื่องบ้าน[/direct]
[direct=http://www.herb-health.com]แบบทรงผมข้อมูลด้านสุขภาพ ความงาม[/direct]