|
|
|
| Вот этот код работает в FF OPERA 9.51 но в ИЕ 6 не работает ((
//-------------------------------------------
function loading()
{
document.getElementById('status').innerHTML = "<img src=\"indicator.gif\" />"+"Loading..." ;
}
function ready()
{
document.getElementById('status').innerHTML = "Done.";
}
function error()
{
document.getElementById('status').innerHTML = "Error.Connection Failed.";
}
function out(text)
{
document.getElementById('data').innerHTML = text;
ready();
}
function create_query()
{
//return "text="+encodeURIComponent(document.getElementById('text').value) ;
return "show=true" ;
}
///////////////////////////////////////////////
//-------------------------------------------//
///////////////////////////////////////////////
function create_request_object()
{
if (window.XMLHttpRequest) {
try {
return new XMLHttpRequest();
} catch (e){}
} else if (window.ActiveXObject) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch (e){}
try {
return new ActiveXObject('Microsoft.XMLHTTP');
} catch (e){}
}
return null;
}
function send_request(type,loading,done,fail,data_)
{
var req = create_request_object();
var url = "a.php";
////////////////////////////////////////////////
if(req)
{
////////////////////////////////////////////////
var s = function()
{
switch(req.readyState)
{
case 1:
{
loading();
break;
}
case 4:
{
//try{}catch(e){ alert("Ошибка req.status: "+e.description);}
if(req.status == 200)//true
{
done(req.responseText);
req.abort();
req.onreadystatechange = null;
}else{
fail();
}
//alert(req.responseText);
break;
}
}
}
////////////////////////////////////////////////encodeURI(+Math.random()
switch(type)
{
case 'POST':
{
req.onreadystatechange = s;
req.open('POST',url,true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
req.onreadystatechange = s;
try{
req.send(data_||"for_IE_dummy_parameter=for_IE_dummy_parameter");
}catch(e){alert("161:"+e.description);}
}
case 'GET':
{
req.onreadystatechange = s;
req.open('GET',url+'?r='+Math.random()+'&'+data,true);
// req.setRequestHeader("Content-Type", "text/html; charset=UTF-8")
try{
req.send(null);
}catch(e){}
}
}
////////////////////////////////////////////////
}else{
alert('Error!');
}
}
|
сама страничка
<!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>Документ без названия</title>
<script type="text/javascript" src="my_ajax.js"></script>
</head>
<body>
<a href="#" onclick="send_request('POST',loading,out,error,create_query())" >Edit</a>
<div id="status"></div>
<div id="data"></div>
</body>
</html>
|
a.php
<?
include "../configs/connect.cfg";
include "../lib/database.class";
include "../lib/template.class";
//header('Content-Type: text/html; charset=UTF-8');
echo 'Сегодня <i>'.date("d").' '.$month[(date(m))-1].' '.date("Y").' '.date("H:i:s").'</i>';
$_POST['show'] = true;
if($_POST['show'] || $_POST['edit'])
{
$db = new database(array("host"=>host,"user"=>user,"password"=>password,"db"=>db));//создание подключения к бд
//////
}
//print_r($db_data);
if($_POST['show'])
{
$db_data = $db->query_get("SELECT * FROM news LIMIT 20");
foreach($db_data as $arr)
{
echo "<div><a href=\"#\" onclick=\"opn(edit_".$arr['id'].")\" >Edit</a> ".$arr['id']." - ".$arr['title']."</div>
<div style=\"display:none\" id=\"edit_".$arr['id']."\" >
<div class=\"msg\" >
<div class=\"title\" ><input type=\"text\" value=\"".$arr['title']."\" id=\"title\" /></div>
<div class=\"body\" ><textarea id=\"text\" >".$arr['text']."</textarea></div>
<div style=\"text-align:center\">
<a href=\"#\" onclick=\"update(id)\" >Edit</a>
</div>
</div>
</div>";
}
}
if($_POST['show'] && $_POST['id'])
{
}
if($_POST['edit'] && $_POST['id'])
{
}
?>
|
помогите разобраться
проблема в КРОССБРАУЗЕРНОСТИ | |
|
|
|
|
|
|
|
для: zzDimazz
(21.09.2008 в 22:45)
| | попробуйте добавить
break;
перед
case 'GET': | |
|
|
|
|
|
|
|
для: zzDimazz
(21.09.2008 в 22:45)
| | не хватало
break;
перед
case 'GET':
сильно не присматривался , но попробуйте хотя-бы так
function send_request(type,loading,done,fail,data_)
{
var req = create_request_object();
var url = "a.php";
/////
if(!req) {
alert('Error!');
return 0;
}
////
var s = function()
{
if (req.readyState == 1)
{
loading();
}
if (req.readyState == 4)
{
//try{}catch(e){ alert("Ошибка req.status: "+e.description);}
if(req.status == 200)//true
{
out(req.responseText);
req.abort();
req.onreadystatechange = null;
}else {
fail();
}
//alert(req.responseText);
}
}
///encodeURI(+Math.random()
switch(type)
{
case 'POST':
{
req.onreadystatechange = s;
req.open('POST',url,true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
try{
req.send(data_);
}catch(e){alert("161:"+e.description);}
}
break;
case 'GET':
{
req.onreadystatechange = s;
req.open('GET',url+'?r='+Math.random()+'&'+data,true);
// req.setRequestHeader("Content-Type", "text/html; charset=UTF-8")
try{
req.send(null);
}catch(e){}
}
}
}
|
| |
|
|
|