2012-03-09 59 views
3

我有一個基於php的web應用程序,用戶輸入一個值時,會從mysql數據庫中提取詳細信息並顯示它,而不顯示頁面刷新。這顯然是用JavaScript來完成的。PHP和JavaScript在Internet Explorer和Google Chrome上正常工作,但不在三星Galaxy上Android

這可以在移動設備(如黑莓和平板電腦)上正確運行Internet Explorer,chrome等,格式化會在用戶輸入數據後搞砸。看下面的屏幕截圖。

Internet Explorer中,表結構保持在間歇: enter image description here

移動設備(Galaxy平板),表結構發生變化: enter image description here

example can be viewed here

守則涉及的2頁是如下所示。前端是一個使用javascript從mysql中獲取和顯示數據的php頁面。

PHP頁面:

<html> 
<head> 
<title>test</title> 
<script type="text/javascript"> 
    function showUser(userNumber, str) 
    { 
    document.getElementById("r"+(userNumber)).style.display="block"; 
    if (str=="") 
    { 
     document.getElementById("txtHint1").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("txtHint1").innerHTML=xmlhttp.responseText; 
     } 
    } 
    xmlhttp.open("GET","getdata1.php?q="+str,true); 
    xmlhttp.send(); 
    } 
</script> 
</head> 
<body> 

<form name="orderform" id="orderform" action="newsale.php" method="post"> 

<div align="left" id="txtHint1">mysql data will be shown here</div> 
<br> 
<table border="1"> 

    <tr id="r1"> 
     <td> 
      <input size="8" type="text" id="sku1" name="sku1" onchange="showUser(1, this.value)" > 
     </td> 
     <td> 
      <input type="text" id="qty1" name="qty1" size="3"> 
     </td> 
    </tr> 
    <tr id="r2"> 
     <td> 
      <input size="8" type="text" id="sku2" name="sku2" onchange="showUser(1, this.value)" > 
     </td> 
     <td> 
      <input type="text" id="qty2" name="qty2" size="3" > 
     </td> 
    </tr> 
</table> 

</form> 
</body> 
</html> 

getdata1.php頁面獲取MySQL數據:所有asistance再次

<?php 
$q=$_GET["q"]; 

$con = mysql_connect('localhost', 'user', 'pass'); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 

mysql_select_db("database", $con); 

$sql="SELECT Category, Description,SellingUnits,Grouping,CasesPerPallet,ShrinksPerPallet FROM skudata WHERE packcode = '".$q."'"; 

$result = mysql_query($sql); 


while($row = mysql_fetch_array($result)) 
    { 
    echo "<font color=blue size=2>Description:</font> <font color=red size=2>".$row['Description']."</font>, "; 
    } 

mysql_close($con); 
?> 

謝謝,這是讚賞。

另外,有沒有人有另一個JavaScript,他們可以給我顯示從MySQL的數據?道歉,但我的JavaScript技能是不存在的。

感謝和問候,

+1

請顯示生成的HTML(右鍵單擊 - >查看源代碼) - 它看起來像某個地方有一個未封閉的標籤,雖然它沒有跳出我的身邊。另外,請選擇一個文檔並正確粘貼。 **所有**屬性值應該用引號括起來。應該避免使用''標籤 - 用CSS代替。 – DaveRandom 2012-03-09 10:20:19

+0

謝謝@DaveRandom,我已經更新了這個問題。 – Smudger 2012-03-09 10:33:47

+3

使用標準的html 1.0 strict或html5並使用驗證器來驗證它http://validator.w3.org/ – ZiTAL 2012-03-09 10:34:45

回答

1

的問題是在你的JavaScript的第一行:

document.getElementById("r"+(userNumber)).style.display="block"; 

你是第一個錶行的顯示樣式設置爲block。我認爲你沒有理由這樣做,所以只要刪除該行,並且你的HTML在所有瀏覽器中都能很好地工作,包括三星Galaxy Tab(我在一個實際的平板電腦上測試過)。

作爲一個側面說明,細胞轉移效應也發生在FireFox中(而不再是)。

+0

謝謝Alex,100%。感謝大家花時間和精力投入到像我這樣的白癡身上:-) – Smudger 2012-03-13 13:34:33

相關問題