halli, hallo...
habe ein problem mit meinem script... bzw. meinen scripten..
habe schon herausgefunden wo das problem liegt, jedoch nicht warum es das problem ist. firebug konnte mir keinen grund liefern und das errorlog meines servers ebenfalls nicht...
die folgenden beiden scripte funktionieren und ich erhalte eine ausgabe.
resources.php
resources.tpl:
die nächsten beiden scripte funktionieren nicht, bzw. die ajax datei kommt nur bis readyState 4, das habe ich herausgefunden, indem ich in verschiedenen teilen meines scripts alerts habe ausführen lassen.
ajax.js:
resources.index.php:
schonmal danke für jede hilfe
habe ein problem mit meinem script... bzw. meinen scripten..
habe schon herausgefunden wo das problem liegt, jedoch nicht warum es das problem ist. firebug konnte mir keinen grund liefern und das errorlog meines servers ebenfalls nicht...
die folgenden beiden scripte funktionieren und ich erhalte eine ausgabe.
resources.php
PHP-Code:
<?php
require('./php_library/inc/config.inc.php');
header('Content-Type: text/xml');
switch($_GET['page']){
case "resources":
$sql = "SELECT * FROM `cw_resources` WHERE `uid` = '2'";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
$res[] = $row;
}
$tpl->assign('resources', $res);
$tpl->display('resources.tpl');
break;
}
?>
<?xml version='1.0' encoding='iso-8859-1' ?>
{foreach from=$resources item=res}
<resources>
<credits>{$res.credits}</credits>
<citizens>{$res.citizens}</citizens>
<iron>{$res.iron}</iron>
<titanium>{$res.titanium}</titanium>
<silicon>{$res.silicon}</silicon>
<hydrogen>{$res.hydrogen}</hydrogen>
<ore>{$res.ore}</ore>
<sponge>{$res.sponge}</sponge>
<quartz>{$res.quartz}</quartz>
<diamond>{$res.diamond}</diamond>
<octanium>{$res.octanium}</octanium>
<energy>{$res.energy}</energy>
</resources>
{/foreach}
{foreach from=$resources item=res}
<resources>
<credits>{$res.credits}</credits>
<citizens>{$res.citizens}</citizens>
<iron>{$res.iron}</iron>
<titanium>{$res.titanium}</titanium>
<silicon>{$res.silicon}</silicon>
<hydrogen>{$res.hydrogen}</hydrogen>
<ore>{$res.ore}</ore>
<sponge>{$res.sponge}</sponge>
<quartz>{$res.quartz}</quartz>
<diamond>{$res.diamond}</diamond>
<octanium>{$res.octanium}</octanium>
<energy>{$res.energy}</energy>
</resources>
{/foreach}
ajax.js:
var req = createXMLHttpRequest();
var cron1 = window.setInterval("get_resources()", 10000);
function createXMLHttpRequest() {
http_request = false;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
return false;
}
}
function get_resources()
{
http_request.open('get', 'resources.php?page=resources', true);
http_request.onreadystatechange = get_resources_php();
http_request.send(null);
}
function get_resources_php() {
if(http_request.readyState == 4){ <- !!! nachfolgender code wird nicht ausgeführt
alert("asasa");
var xmldoc = http_request.respon************ML;
var root = xmldoc.getElementsByTagName('resources').item(0);
var res_credits = root.getElementsByTagName('credits').item(0);
var res_citizens = root.getElementsByTagName('citizens').item(0);
var res_iron = root.getElementsByTagName('iron').item(0);
var res_titanium = root.getElementsByTagName('titanium').item(0);
var res_silicon = root.getElementsByTagName('silicon').item(0);
var res_hydrogen = root.getElementsByTagName('hydrogen').item(0);
var res_ore = root.getElementsByTagName('ore').item(0);
var res_sponge = root.getElementsByTagName('sponge').item(0);
var res_quartz = root.getElementsByTagName('quartz').item(0);
var res_diamond = root.getElementsByTagName('diamond').item(0);
var res_octanium = root.getElementsByTagName('octanium').item(0);
div = document.getElementById('res_credits');
div.innerHTML = res_credits.firstChild.data;
div = document.getElementById('res_citizens');
div.innerHTML = res_citizens.firstChild.data;
div = document.getElementById('res_iron');
div.innerHTML = res_iron.firstChild.data;
div = document.getElementById('res_titanium');
div.innerHTML = res_titanium.firstChild.data;
div = document.getElementById('res_silicon');
div.innerHTML = res_silicon.firstChild.data;
div = document.getElementById('res_hydrogen');
div.innerHTML = res_hydrogen.firstChild.data;
div = document.getElementById('res_ore');
div.innerHTML = res_ore.firstChild.data;
div = document.getElementById('res_sponge');
div.innerHTML = res_sponge.firstChild.data;
div = document.getElementById('res_quartz');
div.innerHTML = res_quartz.firstChild.data;
div = document.getElementById('res_diamond');
div.innerHTML = res_diamond.firstChild.data;
div = document.getElementById('res_octanium');
div.innerHTML = res_octanium.firstChild.data;
}
}
var cron1 = window.setInterval("get_resources()", 10000);
function createXMLHttpRequest() {
http_request = false;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
return false;
}
}
function get_resources()
{
http_request.open('get', 'resources.php?page=resources', true);
http_request.onreadystatechange = get_resources_php();
http_request.send(null);
}
function get_resources_php() {
if(http_request.readyState == 4){ <- !!! nachfolgender code wird nicht ausgeführt
alert("asasa");
var xmldoc = http_request.respon************ML;
var root = xmldoc.getElementsByTagName('resources').item(0);
var res_credits = root.getElementsByTagName('credits').item(0);
var res_citizens = root.getElementsByTagName('citizens').item(0);
var res_iron = root.getElementsByTagName('iron').item(0);
var res_titanium = root.getElementsByTagName('titanium').item(0);
var res_silicon = root.getElementsByTagName('silicon').item(0);
var res_hydrogen = root.getElementsByTagName('hydrogen').item(0);
var res_ore = root.getElementsByTagName('ore').item(0);
var res_sponge = root.getElementsByTagName('sponge').item(0);
var res_quartz = root.getElementsByTagName('quartz').item(0);
var res_diamond = root.getElementsByTagName('diamond').item(0);
var res_octanium = root.getElementsByTagName('octanium').item(0);
div = document.getElementById('res_credits');
div.innerHTML = res_credits.firstChild.data;
div = document.getElementById('res_citizens');
div.innerHTML = res_citizens.firstChild.data;
div = document.getElementById('res_iron');
div.innerHTML = res_iron.firstChild.data;
div = document.getElementById('res_titanium');
div.innerHTML = res_titanium.firstChild.data;
div = document.getElementById('res_silicon');
div.innerHTML = res_silicon.firstChild.data;
div = document.getElementById('res_hydrogen');
div.innerHTML = res_hydrogen.firstChild.data;
div = document.getElementById('res_ore');
div.innerHTML = res_ore.firstChild.data;
div = document.getElementById('res_sponge');
div.innerHTML = res_sponge.firstChild.data;
div = document.getElementById('res_quartz');
div.innerHTML = res_quartz.firstChild.data;
div = document.getElementById('res_diamond');
div.innerHTML = res_diamond.firstChild.data;
div = document.getElementById('res_octanium');
div.innerHTML = res_octanium.firstChild.data;
}
}
<HTML>
<HEAD><title>Ajax-test</title>
<script language="JavaScript" src="ajax.js" type="text/javascript"></script>
</HEAD>
<BODY onload="get_resources()">
<div id="res_credits"></div>
<div id="res_citizens"></div>
<div id="res_iron"></div>
<div id="res_titanium"></div>
<div id="res_silicon"></div>
<div id="res_hydrogen"></div>
<div id="res_ore"></div>
<div id="res_sponge"></div>
<div id="res_quartz"></div>
<div id="res_diamond"></div>
<div id="res_octanium"></div>
</BODY>
</HTML>
<HEAD><title>Ajax-test</title>
<script language="JavaScript" src="ajax.js" type="text/javascript"></script>
</HEAD>
<BODY onload="get_resources()">
<div id="res_credits"></div>
<div id="res_citizens"></div>
<div id="res_iron"></div>
<div id="res_titanium"></div>
<div id="res_silicon"></div>
<div id="res_hydrogen"></div>
<div id="res_ore"></div>
<div id="res_sponge"></div>
<div id="res_quartz"></div>
<div id="res_diamond"></div>
<div id="res_octanium"></div>
</BODY>
</HTML>
schonmal danke für jede hilfe
Kommentar