JavaScript - &getJSON no regresa respuesta

 
Vista:
sin imagen de perfil

&getJSON no regresa respuesta

Publicado por Javier Diego (8 intervenciones) el 23/06/2017 06:00:09
Tengo el siguiete codigo pero no me regresa respuesta el metodo getjson


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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
$diez;
$nueve;
$fecha=$_POST[vnom];
$mysqli = new mysqli("localhost", "root", "12345678", "prueba");
 
/*Y llamamos al procedimiento para hacer la inserción*/
/*Si falla imprimimos el error*/
if (!$mysqli->query("CALL dia('$fecha')")) {
    echo "Falló la llamada: (" . $mysqli->errno . ") " . $mysqli->error;
}else{
 
}
 
 
 
 
if (!$resultado = $mysqli->query("select avg(temperatura) from diat where hora<'23:00:00' and hora>'22:00:00'")) {
    // ¡Oh, no! La consulta falló. 
    echo "Lo sentimos, este sitio web está experimentando problemas.";
 
    // De nuevo, no hacer esto en un sitio público, aunque nosotros mostraremos
    // cómo obtener información del error
    echo "Error: La ejecución de la consulta falló debido a: \n";
    echo "Query: " . $sql . "\n";
    echo "Errno: " . $mysqli->errno . "\n";
    echo "Error: " . $mysqli->error . "\n";
    exit;
}
 
if (!$resultado2 = $mysqli->query("select avg(temperatura) from diat where hora<'22:00:00' and hora>'21:00:00'")) {
    // ¡Oh, no! La consulta falló. 
    echo "Lo sentimos, este sitio web está experimentando problemas.";
 
    // De nuevo, no hacer esto en un sitio público, aunque nosotros mostraremos
    // cómo obtener información del error
    echo "Error: La ejecución de la consulta falló debido a: \n";
    echo "Query: " . $sql . "\n";
    echo "Errno: " . $mysqli->errno . "\n";
    echo "Error: " . $mysqli->error . "\n";
    exit;
}
 
 
 
 
//print_r($array);
while($row = $resultado->fetch_array())
{
$rows[] = $row;
$diez=$row[0];
}
 
foreach($rows as $row)
{
echo $row['avg(temperatura)'];
}
 
 
while($row2 = $resultado2->fetch_array())
{
$rows2[] = $row2;
$nueve=$row2[0];
}
 
foreach($rows2 as $row2)
{
echo $row2['avg(temperatura)'];
}
 
$arrayT = array(
    "diez" => $diez,
    "n" => $nueve,
);
 
echo json_encode($arrayT);
 
/*echo $array['d'].$array['n'];

echo "ok";*/
?>
 
---------
empieza index
---------------------
 
<html>
  <head>
  <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
  <form class="cmxform" id="commentForm" method="get">
  <p>
		<label for="nom">Fecha</label>
		<input id="nom" name="Nombre" type="text" required>
	</p>
 
    <p>
		<input class="Submit" type="Submit" value="Evaluar" id="Entrar">
	</p>
 
    </form>
 
    <script src="vendor/jquery/jquery.min.js"></script>
 
    <script language="JavaScript" src="js/jquery-2.1.1.min.js"></script>
 
<script src="js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
 
    <!-- Contact Form JavaScript-->
    <script src="js/jqBootstrapValidation.js"></script>
 
    <script src="js/contact_me.js"></script>
 
    <!-- Theme JavaScript -->
    <script src="js/freelancer.min.js"></script>
 
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
var prueba;
var paso;
 
var vnom;
 
 
	$(document).ready(function() {
		$("#commentForm").submit(function(e) {
			e.preventDefault();
 
			alert("funciono");
 
			/*var vcon = $("#contra").val();
			var vrol = $("#rol").val();*/
			vnom = $("#nom").val();
			alert(vnom);
			//prueba=130;
			/*var vapp = $("#app").val();
			var vapm = $("#apm").val();
			var vcor = $("#cemail").val();
			var formData = {
				contrasena: vcon,
				rol: vrol,
				nombre: vnom,
				paterno: vapp,
				materno: vapm,
				correo: vcor
			};
			$.post("registro1.php", formData, function(response) {
				alert(response);
			});*/
 
		//grafica
 
		$.getJSON("baseg.php",{vnom:vnom},function(arrayT){
 
		prueba=arrayT[0].diez;
 
		alert(arrayT);
		//	$_SESSION['idUsuario'] = resultado[0].nombre;
		//$_SESSION['idUsuario'] = $name;
		//window.location =("pagina1.php");
 
		//alert("Bienvenido "+resultado[0].nombre);
 
		//$.post("prueba.php",{txtusuario:txtusuario});
 
		//alert("Bienvenido "+resultado[1].apPaternno);
		//window.location=("prueba.php");
		//window.location=("pagina1.php");
		});
 
		google.charts.load('current', {'packages':['bar']});
    google.charts.setOnLoadCallback(drawChart);
 
    function drawChart() {
 
      var data = new google.visualization.DataTable();
      data.addColumn('timeofday', 'Hora');
      data.addColumn('number', 'Temperatura');
 
      data.addRows([
	    [[-7, 30, 45], 10],
        [[7, 30, 45], 5],
        [[9, 0, 0], prueba],
        [[10, 0, 0, 0], 12],
        [[10, 45, 0, 0], 13],
        [[11, 0, 0, 0], 15],
        [[12, 15, 45, 0], 20],
        [[13, 0, 0, 0], 22],
        [[14, 30, 0, 0], 25],
        [[15, 12, 0, 0], 30],
        [[16, 45, 0], 32],
        [[16, 59, 0], 42]
 
      ]);
 
      var options = {
        title: 'Historial temperatura',
        height: 450
      };
 
      var chart = new google.charts.Bar(document.getElementById('chart_div'));
 
      chart.draw(data, google.charts.Bar.convertOptions(options));
 
    }
 
 
 
		//grafica
 
		});
	});
 
    </script>
  </head>
 
  <body>
<!--Div that will hold the pie chart-->
    <div id="chart_div" style="width:400; height:300"></div>
 
  </body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

$.getJSON no regresa respuesta

Publicado por Javier Diego (8 intervenciones) el 23/06/2017 06:27:17
LO SUBO SIN CODIGO COMENTARIADO

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
<?php
$diez;
$nueve;
$fecha=$_POST[vnom];
$mysqli = new mysqli("localhost", "root", "12345678", "prueba");
 
/*Y llamamos al procedimiento para hacer la inserción*/
/*Si falla imprimimos el error*/
if (!$mysqli->query("CALL dia('$fecha')")) {
echo "Falló la llamada: (" . $mysqli->errno . ") " . $mysqli->error;
}else{
 
}
 
 
 
 
if (!$resultado = $mysqli->query("select avg(temperatura) from diat where hora<'23:00:00' and hora>'22:00:00'")) {
// ¡Oh, no! La consulta falló. 
echo "Lo sentimos, este sitio web está experimentando problemas.";
 
// De nuevo, no hacer esto en un sitio público, aunque nosotros mostraremos
// cómo obtener información del error
echo "Error: La ejecución de la consulta falló debido a: \n";
echo "Query: " . $sql . "\n";
echo "Errno: " . $mysqli->errno . "\n";
echo "Error: " . $mysqli->error . "\n";
exit;
}
 
if (!$resultado2 = $mysqli->query("select avg(temperatura) from diat where hora<'22:00:00' and hora>'21:00:00'")) {
// ¡Oh, no! La consulta falló. 
echo "Lo sentimos, este sitio web está experimentando problemas.";
 
// De nuevo, no hacer esto en un sitio público, aunque nosotros mostraremos
// cómo obtener información del error
echo "Error: La ejecución de la consulta falló debido a: \n";
echo "Query: " . $sql . "\n";
echo "Errno: " . $mysqli->errno . "\n";
echo "Error: " . $mysqli->error . "\n";
exit;
}
 
 
 
 
//print_r($array);
while($row = $resultado->fetch_array())
{
$rows[] = $row;
$diez=$row[0];
}
 
foreach($rows as $row)
{
echo $row['avg(temperatura)'];
}
 
 
while($row2 = $resultado2->fetch_array())
{
$rows2[] = $row2;
$nueve=$row2[0];
}
 
foreach($rows2 as $row2)
{
echo $row2['avg(temperatura)'];
}
 
$arrayT = array(
"diez" => $diez,
"n" => $nueve,
);
 
echo json_encode($arrayT);
 
/*echo $array['d'].$array['n'];

echo "ok";*/
?>

EMPIEZA GRAFICA.HTML


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
<html>
  <head>
  <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
  <form class="cmxform" id="commentForm" method="get">
  <p>
		<label for="nom">Fecha</label>
		<input id="nom" name="Nombre" type="text" required>
	</p>
 
    <p>
		<input class="Submit" type="Submit" value="Evaluar" id="Entrar">
	</p>
 
    </form>
 
    <script src="vendor/jquery/jquery.min.js"></script>
 
    <script language="JavaScript" src="js/jquery-2.1.1.min.js"></script>
 
<script src="js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
 
    <!-- Contact Form JavaScript-->
    <script src="js/jqBootstrapValidation.js"></script>
 
    <script src="js/contact_me.js"></script>
 
    <!-- Theme JavaScript -->
    <script src="js/freelancer.min.js"></script>
 
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
var prueba;
var paso;
 
var vnom;
 
	$(document).ready(function() {
		$("#commentForm").submit(function(e) {
			e.preventDefault();
 
			alert("funciono");
 
 
			vnom = $("#nom").val();
			alert(vnom);
 
 
		//grafica
 
		$.getJSON("baseg.php",{vnom:vnom},function(arrayT){
 
				prueba=arrayT[0].diez;
 
				alert(arrayT);
 
				});
 
		google.charts.load('current', {'packages':['bar']});
    google.charts.setOnLoadCallback(drawChart);
 
    function drawChart() {
 
      var data = new google.visualization.DataTable();
      data.addColumn('timeofday', 'Hora');
      data.addColumn('number', 'Temperatura');
 
      data.addRows([
	    [[-7, 30, 45], 10],
        [[7, 30, 45], 5],
        [[9, 0, 0], prueba],
        [[10, 0, 0, 0], 12],
        [[10, 45, 0, 0], 13],
        [[11, 0, 0, 0], 15],
        [[12, 15, 45, 0], 20],
        [[13, 0, 0, 0], 22],
        [[14, 30, 0, 0], 25],
        [[15, 12, 0, 0], 30],
        [[16, 45, 0], 32],
        [[16, 59, 0], 42]
 
 
      ]);
 
      var options = {
        title: 'Historial temperatura',
        height: 450
      };
 
      var chart = new google.charts.Bar(document.getElementById('chart_div'));
 
      chart.draw(data, google.charts.Bar.convertOptions(options));
 
    }
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

$.getJSON no regresa respuesta

Publicado por Javier Diego (8 intervenciones) el 23/06/2017 07:20:51
Ya logre la respuesta pero no consigo que me almacene el dato en la variable prueba.

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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
$diez;
$nueve;
$fecha=$_POST[vnom];
$mysqli = new mysqli("localhost", "root", "12345678", "prueba");
 
/*Y llamamos al procedimiento para hacer la inserción*/
/*Si falla imprimimos el error*/
if (!$mysqli->query("CALL dia('$fecha')")) {
    echo "Falló la llamada: (" . $mysqli->errno . ") " . $mysqli->error;
}else{
 
}
 
 
 
 
if (!$resultado = $mysqli->query("select avg(temperatura) from diat where hora<'23:00:00' and hora>'22:00:00'")) {
    // ¡Oh, no! La consulta falló. 
    echo "Lo sentimos, este sitio web está experimentando problemas.";
 
    // De nuevo, no hacer esto en un sitio público, aunque nosotros mostraremos
    // cómo obtener información del error
    echo "Error: La ejecución de la consulta falló debido a: \n";
    echo "Query: " . $sql . "\n";
    echo "Errno: " . $mysqli->errno . "\n";
    echo "Error: " . $mysqli->error . "\n";
    exit;
}
 
if (!$resultado2 = $mysqli->query("select avg(temperatura) from diat where hora<'22:00:00' and hora>'21:00:00'")) {
    // ¡Oh, no! La consulta falló. 
    echo "Lo sentimos, este sitio web está experimentando problemas.";
 
    // De nuevo, no hacer esto en un sitio público, aunque nosotros mostraremos
    // cómo obtener información del error
    echo "Error: La ejecución de la consulta falló debido a: \n";
    echo "Query: " . $sql . "\n";
    echo "Errno: " . $mysqli->errno . "\n";
    echo "Error: " . $mysqli->error . "\n";
    exit;
}
 
 
 
 
//print_r($array);
while($row = $resultado->fetch_array())
{
$rows[] = $row;
$diez=$row[0];
}
 
foreach($rows as $row)
{
echo $row['avg(temperatura)'];
}
 
 
while($row2 = $resultado2->fetch_array())
{
$rows2[] = $row2;
$nueve=$row2[0];
}
 
foreach($rows2 as $row2)
{
echo $row2['avg(temperatura)'];
}
 
$arrayT[] = array("diez" => $diez);
   $arrayT[] = array ("n" => $nueve);
 
 
echo json_encode($arrayT);
 
/*echo $array['d'].$array['n'];

echo "ok";*/
?>
------------------------------------------------------------------------------------
empeiza index
---------------------------------------------------------------------------------------
<html>
  <head>
  <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
  <form class="cmxform" id="commentForm" method="get">
  <p>
				<label for="nom">Fecha</label>
				<input id="nom" name="Nombre" type="text" required>
			</p>
 
            <p>
				<input class="Submit" type="Submit" value="Evaluar" id="Entrar">
			</p>
 
            </form>
 
            <script src="vendor/jquery/jquery.min.js"></script>
 
            <script language="JavaScript" src="js/jquery-2.1.1.min.js"></script>
 
<script src="js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>
 
    <!-- Contact Form JavaScript-->
    <script src="js/jqBootstrapValidation.js"></script>
 
    <script src="js/contact_me.js"></script>
 
    <!-- Theme JavaScript -->
    <script src="js/freelancer.min.js"></script>
 
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
var prueba;
var paso;
 
var vnom;
 
 
	$(document).ready(function() {
		$("#commentForm").submit(function(e) {
			e.preventDefault();
 
			alert("funciono");
 
 
			vnom = $("#nom").val();
			alert(vnom);
 
		//grafica
 
		$.getJSON("baseg.php",{vnom:vnom},function(arrayT){
 
			alert(arrayT);
			prueba=arrayT[0].diez;
		});
 
		google.charts.load('current', {'packages':['bar']});
    google.charts.setOnLoadCallback(drawChart);
 
    function drawChart() {
 
      var data = new google.visualization.DataTable();
      data.addColumn('timeofday', 'Hora');
      data.addColumn('number', 'Temperatura');
 
      data.addRows([
	    [[-7, 30, 45], 10],
        [[7, 30, 45], 5],
        [[9, 0, 0], prueba],
        [[10, 0, 0, 0], 12],
        [[10, 45, 0, 0], 13],
        [[11, 0, 0, 0], 15],
        [[12, 15, 45, 0], 20],
        [[13, 0, 0, 0], 22],
        [[14, 30, 0, 0], 25],
        [[15, 12, 0, 0], 30],
        [[16, 45, 0], 32],
        [[16, 59, 0], 42]
 
 
      ]);
 
      var options = {
        title: 'Historial temperatura',
        height: 450
      };
 
      var chart = new google.charts.Bar(document.getElementById('chart_div'));
 
      chart.draw(data, google.charts.Bar.convertOptions(options));
 
    }
 
		//grafica
 
		});
	});
 
 
    </script>
  </head>
 
  <body>
<!--Div that will hold the pie chart-->
    <div id="chart_div" style="width:400; height:300"></div>
 
  </body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar