[英]I have table that i use to update mysql via ajax or jquery and works for firefox,opera,chrome and safari but not IE8
[英]Works in Firefox & Opera, but not in IE8
1)此問題僅涉及一個html網頁,我們稱其為“ ajax.html”。
2)我在此網頁中具有AJAX功能,可同時在Firefox和IE8中使用。
3)現在,我嘗試使用ajax函數僅生成日期下拉列表的選項值,並且它在Firefox和Opera中起作用,但不適用於IE8。
4)下拉菜單的周圍html代碼如下所示:
<select name="entry_7_single" id="entry_7" onChange="Ajax_PhpResultsWithVar('./secure/db/SummaryCls.php','entry_8','dateval',this.value)"></select>
onchange調用是指ajax函數,該函數成功(Firefox和IE8都)使用與該下拉列表中選擇的日期相關的事件描述來填充文本區域(entry_8)。
5)一個onload調用啟動ajax函數來生成下拉列表值:
<body class="ss-base-body" onLoad="OnLoadWebPage()">
6)調用ajax函數的js腳本如下:
function OnLoadWebPage()
{
Ajax_PhpResults('./secure/db/GenDateListCls.php','entry_7');
}
7)由於它可以在Firefox中運行,但不能在IE8中運行,因此我將ajax函數的輸出放入Firefox大文本框中,並得到以下信息:
<option selected value="8 JUN 2010">8 JUN 2010</option>
<option value="9 JUN 2010">9 JUN 2010</option>
<option value="10 JUN 2010">10 JUN 2010</option>
<option value="11 JUN 2010">11 JUN 2010</option>
8)生成了上百種,但是您可以了解ajax函數生成的內容。 接下來,我將列出輸出上述下拉值的PHP函數:
<?php
include_once 'SPSQLite.class.php';
include_once 'misc_funcs.php';
class GenDateListCls
{
var $dbName;
var $sqlite;
function GenDateListCls()
{
$this->dbName = 'accrsc.db';
$this->ConstructEventDates();
}
function ConstructEventDates()
{
$this->sqlite = new SPSQLite($this->dbName);
$todayarr = getdate();
$today = $todayarr[mday] . " " . substr($todayarr[month],0,3) . " " . $todayarr[year];
$ICalDate = ChangeToICalDate($today);
$dateQuery = "SELECT dtstart from events where substr(dtstart,1,8) >= '" . $ICalDate . "';";
$this->sqlite->query($dateQuery);
$datesResult = $this->sqlite->returnRows();
foreach (array_reverse($datesResult) as $indx => $row)
{
$normDate = NormalizeICalDate(substr($row[dtstart],0,8));
if ($indx==0)
{
?>
<option selected value=<?php echo('"' . $normDate . '"'); ?>><?php echo $normDate; ?></option>
<?php
}
else
{
?>
<option value=<?php echo('"' . $normDate . '"'); ?>><?php echo $normDate; ?></option>
<?php
}
}
$this->sqlite->close();
}
}
$dateList = new GenDateListCls();
?>
9)這是我創建和使用的ajax函數(當然,某些部分是從網絡示例中修改的):
function Ajax_XMLHttpRequest_Factory()
{
var ajxRequest;
try
{
// Opera 8.0+, Firefox, Safari
ajxRequest = new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer Browsers
try
{
ajxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
// Something went wrong
alert("Unable to create an XMLHttpRequest with this current browser.");
return false;
}
}
}
return ajxRequest;
}
function Ajax_PhpResults(fname,elementID){
var ajaxRequest = Ajax_XMLHttpRequest_Factory();
// Create a callback function that will receive data sent from the server
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById(elementID);
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", fname, true);
ajaxRequest.send();
}
function Ajax_PhpResultsWithVar(fname,elementID,varpassed,value){
var ajaxRequest = Ajax_XMLHttpRequest_Factory();
// Create a callback function that will receive data sent from the server
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById(elementID);
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", fname+"?"+varpassed+"="+value, true);
ajaxRequest.send();
}
function Ajax_RunPhpOnly(fname){
var ajaxRequest = Ajax_XMLHttpRequest_Factory();
ajaxRequest.open("GET", fname, true);
ajaxRequest.send(null);
}
感謝您對此事的協助。
我的背景:眾所周知,我是PHP,Ajax和javascript的一個完整的新手,並且我自己學習它,沒有任何類。 我的背景是Linux,Windows,C ++,Java,VB,VBA,MS XML和一些HTML。
嘗試不使用innerHTML
。 IE歷來不允許您在可能的任何地方使用innerHTML
。 而是嘗試使用速度較慢,笨拙的DOM方法.appendChild()
。 例如,讓PHP返回帶有所需值/文本對的JSON或XML,然后在進行AJAX時執行以下操作:
PHP輸出(又名您的http.responseText
):
{value:"20100608",text:"date 1"},
{value:"20100609",text:"date 2"},
{value:"20100610",text:"date 3"},
{value:"20100611",text:"date 4"},
{value:"20100612",text:"date 5"}
JavaScript:
http.onreadystatechange = function(){
if(http.readyState == 4){
eval("var data = [" + http.responseText + "]");
for(var i=0;i<data.length;i++)
var t = document.createElement("option");
t.value = data[i].value;
t.innerHTML = data[i].text;
document.getElementById("entry_7").appendChild(t);
}
}
}
我不確定為什么會遇到問題,但是我想這與IE中select
元素的innerHTML
有關。 試試我上面的方法,我很確定它會起作用。
我希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.