bucle for con ajax div
Publicado por tutox (1 intervención) el 20/10/2015 00:25:04
Hola el problema con mi codigo es que solo me devuelve el contenido del ajax div en un solo index del bucle, ejemplo: si son 2 index que debe imprimir el bucle, solo me imprime el contenido en el primer index...
index.php
ajax.js
file1.php
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html>
<head>
<title>DeportesRulz.com</title>
<link charset="utf-8" href="./css/tablaodds.css" media="screen" rel="stylesheet" type="text/css" />
<script src="./js/ajax.js"></script>
</head>
<body>
<script type='text/javascript'>refreshdiv_live();</script>
<?php
//Obtener fecha
date_default_timezone_set('America/Caracas');
$fechaabrev = strftime("Sat, %b 17, %y");
//[Variables globales]
$xml = simplexml_load_file('http://sportsfeeds.bovada.lv/basic/MLB.xml');
$juegos = count($xml->EventType->Date);
//Obtener todos los juegos
for ($i=0;$i<=$juegos-1;$i++) {
//Obtener solo juegos del dia
if ($xml->EventType->Date[$i]->attributes()->DTEXT == $fechaabrev){
$juegosdeldia = count($xml->EventType->Date[$i]->Event);
//Bucle principal juegos del dia
for ($k=0;$k<=$juegosdeldia-1;$k++) {
$juego_dia = $xml->EventType->Date[$i]->attributes()->DTEXT.' ';
$juego_horaf = $xml->EventType->Date[$i]->Event[$k]->Time->attributes()->TTEXT.' ';
$juego_horaf = explode(" ", $juego_horaf);
$juego_hora = $juego_horaf[0];
$juego_live = $xml->EventType->Date[$i]->Event[$k]->attributes()->LIVE_ENABLED.' ';
$juego_ligaf = $xml->EventType->Date[$i]->Event[$k]->NOTE.' ';
$juego_ligaf = explode(" ", $juego_ligaf);
if ($juego_ligaf[0] == 'AMERICAN'){
$juego_liga = 'American League';
} else if ($juego_ligaf[0] == 'NATIONAL'){
$juego_liga = 'National League';
}
$equipos = count($xml->EventType->Date[$i]->Event[$k]->Competitor);
//Bucle equipos
for ($j=0;$j<=$equipos-1;$j++) {
//Obtener equipo A
if ($xml->EventType->Date[$i]->Event[$k]->Competitor[$j]->attributes()->NUM == 2){
$equipo_a = $xml->EventType->Date[$i]->Event[$k]->Competitor[$j]->attributes()->NAME;
}//--Fin Obtener equipo A--
//Obtener equipo B
if ($xml->EventType->Date[$i]->Event[$k]->Competitor[$j]->attributes()->NUM == 1){
$equipo_b = $xml->EventType->Date[$i]->Event[$k]->Competitor[$j]->attributes()->NAME;
}//--Fin Obtener equipo B--
}//--Fin Bucle equipos--
//--------------------------------------------[Imprimiendo datos]---------------------------------------------------------//
echo "<table cellpadding='3' cellspacing='1' class='tablehead' style='background-color:white;'><tbody><tr class='stathead'><td colspan='5' style='background-color:#0B3861;color:white;'>$equipo_a vs $equipo_b | [MLB] $juego_liga <div name='live[$k]' id='live'></div></tr><tr class='colhead' style='text-align:center;'><td>$juego_hora</td><td>A GANAR</td><td>ALTA/BAJA (6.5)</td><td>RUN LINE</td><td>ALTA/BAJA (3.5 | 5to inning)</td></tr><div id='odds'></div></tbody></table>";
//------------------------------------------[Fin Imprimiendo datos]---------------------------------------------------------//
}//--Fin Bucle principal juegos del dia--
}//--Fin Obtener solo juegos del dia--
}//--Fin Obtener todos los juegos--
?>
</body>
</html>
ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Create multiple XMLHttpRequest objects (one for each DIV)
// The AJAX function...
function AJAX(){
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
return xmlHttp;
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
}
// Timestamp for preventing IE caching the GET request (common function)
function fetch_unix_timestamp()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}
////////////////////////////////
//
// Refreshing the DIV TIMEDIV
//
////////////////////////////////
function refreshdiv_timediv(){
// Customise those settings
var seconds = '5';
var divid = "timediv";
var url = "boo.php";
var xmlHttp_one = AJAX();
// No cache
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// The code...
xmlHttp_one.onreadystatechange=function(){
if(xmlHttp_one.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
setTimeout('refreshdiv_timediv()',seconds*1000);
}
}
xmlHttp_one.open("GET",nocacheurl,true);
xmlHttp_one.send(null);
}
// Start the refreshing process
window.onload = function startrefresh(){
setTimeout('refreshdiv_timediv()',seconds*1000);
}
////////////////////////////////
//
// Refreshing the DIV TIMEINWASHINGTON
//
////////////////////////////////
function refreshdiv_timeinwashington(){
// Customise those settings
var seconds = 8;
var divid = "timeinwashington";
var url = "boo2.php";
var xmlHttp_two = AJAX();
// No cache
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// The code...
xmlHttp_two.onreadystatechange=function(){
if(xmlHttp_two.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_two.responseText;
setTimeout('refreshdiv_timeinwashington()',seconds*1000);
}
}
xmlHttp_two.open("GET",nocacheurl,true);
xmlHttp_two.send(null);
}
// Start the refreshing process
window.onload = function startrefresh(){
setTimeout('refreshdiv_timeinwashington()',seconds*1000);
}
////////////////////////////////
//
// Refreshing the DIV OTHERDIV
//
////////////////////////////////
function refreshdiv_otherdiv(){
// Customise those settings
var seconds = 5;
var divid = "live";
var url = "file1.php";
var xmlHttp_three = AJAX();
// No cache
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// The code...
xmlHttp_three.onreadystatechange=function(){
if(xmlHttp_three.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp_three.responseText;
setTimeout('refreshdiv_otherdiv()',seconds*1000);
}
}
xmlHttp_three.open("GET",nocacheurl,true);
xmlHttp_three.send(null);
}
// Start the refreshing process
var seconds;
window.onload = function startrefresh(){
setTimeout('refreshdiv_otherdiv()',seconds*1000);
}
file1.php
1
2
3
<?php
echo rand();
?>
Valora esta pregunta


0