標籤:ajax 瀏覽器 xmlhttprequest php 緩衝
1、現在的瀏覽器都比較智能化,當資料庫的資料有變化時,不會讀取網頁上的快取資料,通過以下代碼實現資料庫的訪問:
var thePage = ‘servesql.php‘;
myRand = parseInt(Math.random()*9999999999999999);
var theURL = thePage +"?rand="+myRand;
xmlhttp.open("GET", theURL ,true);
xmlhttp.onreadystatechange = GetXmlTextByTagName;
結果是無法資料到資料庫的內容,可能是瀏覽器不支援這種方式,在chrome, 核心版本為IE6.0的Internet Explorer上都不支援這種方式。
參考網址:http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_send.asp
2、在WAMP上的配置上,調試php時能讓在網頁上顯示調試錯誤:
在php.ini啟動這兩項:display_errors = On && error_reporting = E_ALL
3、php.ini-production 與 php.ini-development的區別:
如果將php.ini-production改成php.ini時,預設調試資訊在網頁上是不顯示的,所以如果是用php進行開發調試時最好還是將 php.ini-development改為php.ini。
4、pdo串連資料庫後關閉方法:
$pdo = new PDO($dsn);
$pdo = null;//這樣就關閉了
5、錯誤:Fatal error: Call to a member function fetchAll() on a non-objec
一般是串連資料庫的地址出現錯誤或資料庫裡無資料。
6、錯誤:error on line 1 at column 1: Document is empty。
當用php寫入xml檔案時,不允許在header()函數前有輸出功能 ,例:var_dump($sth),不然就將header(‘Content-Type: text/xml‘)中的“text/xml”改成text/json。
<?php
$dbh = new PDO("sqlite:upsdata.dat", null, null);
$sth = $dbh->query(‘SELECT * FROM t_ups_rundata‘);
var_dump($sth);
$result = $sth->fetchAll();
$i=0;
$CountArray=0;
foreach($result[0] as $x=>$x_value)
{
if($i%2==0)
{
$UPSData[$CountArray++]=$x_value;
}
$i++;
}
//print_r ($UPSData);
header(‘Content-Type: text/xml‘);
echo "<?xml version=‘1.0‘ encoding=‘utf-8‘?>";
echo "<clock>";
echo "<timestring>$UPSData[3]</timestring>";
echo "</clock>";
$dbh = null;
?>
7、在使用ajax時 xmlHttp=new XMLHttpRequest()與 xmlHttp.open ()、xmlHttp.send()只能在同一個檔案實現。
8、不同瀏覽器解析xml檔案有不同的方式:http://www.jb51.net/article/20876.htm
9、當寫的網頁檔案在IE6.0上運行時,在文法上沒錯誤,而在操作有錯誤時會直接讓瀏覽器崩潰。
10、問題:在ie6.0上沒實現資料的動態重新整理,通過開啟另一個網頁才能實現資料的重新整理。
解決方案:一般瀏覽器的緩衝設定問題, "每次訪問此頁時檢查"這個選項沒勾上。勾選過程:工具->Internet選項->設定->每次訪問此頁時檢查。
IE緩衝設定四種方式介紹:http://zhidao.baidu.com/link?url=57IkxNpQIGICRCL5r6l5uFSfBwmTqbMA8yj0xCxtfF0S38Am_lrErCuXh8oTKdyn5wTbcdtbU722If6MvnA_BK
11、
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlHttp=new XMLHttpRequest();
var url="responsexml.php";
xmlHttp.open("GET",url,false);
xmlHttp.send(null);
xmlHttp.onreadystatechange=getValue(xmlHttp);
當xmlHttp.open("GET",url,false); xmlHttp.send(null);這兩個函數放在onreadystatechange 後面時會出現資料讀取不到,頁面無資料顯示。具體原因沒找到。
12、 IE5、IE6的ajax的操作方法:
// code for IE6, IE5
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
var url="responsexml.php";
xmlHttp.onreadystatechange=function()
{
if (xmlHttp.readyState==4 && xmlHttp.status==200)
{
xmlDoc=xmlHttp.responseXML;
nodes=xmlDoc.documentElement.childNodes;
InputVoltage.innerHTML = nodes.item(3).text;
OutputVoltage.innerHTML = nodes.item(7).text;
OutputMinVoltage.innerHTML = nodes.item(34).text;
OutputMaxVoltage.innerHTML = nodes.item(33).text;
Frequency.innerHTML = nodes.item(13).text;
xmlHttp = null;
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
網頁開發的階段總結(二)