
Problema con condiciones en JQuery
Publicado por Angel (2 intervenciones) el 02/06/2015 20:17:27
Hola amigos, tengo un problema, tengo una pagina para importar un archivo CSV a Mysql, el archivo ya se importa correctamente, el problema es que tengo dos condiciones:
1.- Cuando el archivo se importa correctamente
2.- Cuando el archivo no se importa
Se importe o no el archivo, siempre me sale el mensaje de ERROR EN LA IMPORTACIÓN DEL CSV, acá les dejo los códigos:
EL FORMULARIO:
ARCHIVO PHP QUE HACE LA IMPORTACIÓN:
ARCHIVO JAVASCRIPT
El código php que está al inicio del formulario es porque estoy estableciendo una sesión, ya lo probé sin eso y el error continua.
Agradezco su ayuda....:)
1.- Cuando el archivo se importa correctamente
2.- Cuando el archivo no se importa
Se importe o no el archivo, siempre me sale el mensaje de ERROR EN LA IMPORTACIÓN DEL CSV, acá les dejo los códigos:
EL FORMULARIO:
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
<?php
include('../php/conexion.php');
if(isset($_SESSION['Codigo_US'])==false or isset($_SESSION['Codigo_AR'])==false){
header('Location: index.php');
}else{
if($_SESSION['Codigo_AR'] == 'ADMIN'){
header('Location: admin.php');
}else{
$nombre = mysql_query("SELECT * FROM usuarios WHERE Codigo_US = '".$_SESSION['Codigo_US']."'");
$nombre2 = mysql_fetch_array($nombre);
}
}
?>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="author" content="Angel Humberto Echeverría Bermúdez"/>
<title>Circuitos del Plan</title>
<link rel="stylesheet" type="text/css" href="../css/hoja.css"/>
<script src="../js/jquery.js"></script>
<script src="../js/myjava.js"></script>
</head>
<body>
<div class="contenedor"> <!-- Inicio contenedor de toda la pagina -->
<div class="cuerpo"> <!-- Inicio cuerpo de la pagina -->
<div class="header"> <!-- Inicio cabecera de la pagina -->
<img src="../recursos/encabezado.png" width="100%" height="120" style="border-radius: 15px;"/>
</div> <!-- Fin cabecera de la pagina -->
<table align="center" width="100%">
<tr>
<td align="left">
<font color="black" face="Century Gothic" style="font-size:10pt; font-weight: bold; width: 100%;">
Bienvenid@: <?php echo $nombre2['Nombre_US']; ?><a href="../php/logout.php"> [Salir]</a>
</font>
</td>
<td align="right">
<font color="black" face="Century Gothic" style="font-size:10pt; font-weight: bold; width: 100%;">
<script languaje="JavaScript">
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new Array("Domingo,","Lunes,","Martes,","Miércoles,","Jueves,","Viernes,","Sábado,")
var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre")
document.write("<font color='black' face='Georgia' style='font-size:8pt'> "+dayarray[day]+" "+daym+" de "+montharray[month]+" de "+year+" </font>")
</script>
</font>
</td>
</tr>
</font>
</table>
<center><h1>IMPORTAR CIRCUITOS DEL PLAN DE MANTENIMIENTO</h1></center>
<br/>
<form id="subida">
<div id="centrar">
<div id="formulario" style="width: 400;">
<br />
<table align="center" cellpadding="15" cellspacing="10" style="color: white; font-weight: bold; margin: 0 auto;">
<tr>
<td>
<input type="file" id="csv" name="csv"/>
</td>
</tr>
<tr align="center">
<td>
<input class="boton" type="submit" value="Importar"/>
</td>
</tr>
<tr>
<td id="respuesta"></td>
</tr>
</table>
</form>
</div>
</div>
<div class="footer"> <!-- Inicio pie de pagina -->
<strong>Todos los derechos reservados © 2015 CORPOELEC - Corporación Eléctrica Nacional RIF. G-20010014-1</strong>
</div> <!-- Fin pie de pagina -->
</div> <!-- Fin cuerpo de la pagina -->
</div> <!-- Fin contenedor de toda la pagina -->
</body>
</html>
ARCHIVO PHP QUE HACE LA IMPORTACIÓN:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
include('conexion.php');
if ($_FILES['csv']['size'] > 0) {
$csv = $_FILES['csv']['tmp_name'];
$handle = fopen($csv,'r');
while ($data = fgetcsv($handle,1000,";")){ /* 1000 = Se define que solo se pueden agregar 1000 registros */
if ($data[0]) {
mysql_query("INSERT INTO circuito_plan (Codigo_CI, Prioridad_CI,Codigo_PM) VALUES('".$data[0]."','".$data[1]."','".$data[2]."') ");
}
}
echo 'OK';
}
?>
ARCHIVO JAVASCRIPT
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
$(function(){
$('#subida').submit(function(){
var comprobar = $('#csv').val().length;
if(comprobar>0){
var formulario = $('#subida');
var archivos = new FormData();
var url = '../php/importarCSV.php';
for (var i = 0; i < (formulario.find('input[type=file]').length); i++) {
archivos.append((formulario.find('input[type="file"]:eq('+i+')').attr("name")),((formulario.find('input[type="file"]:eq('+i+')')[0]).files[0]));
}
$.ajax({
url: url,
type: 'POST',
contentType: false,
data: archivos,
processData:false,
beforeSend : function (){
$('#respuesta').html('<center><img src="../recursos/cargando.gif" width="40" heigh="40"></center>');
},
success: function(data){
if(data == 'OK'){
$('#respuesta').html('<label style="padding-top:10px; color:green;">IMPORTACIÓN DE CSV EXITOSA</label>');
return false;
}else {
$('#respuesta').html('<label style="padding-top:10px; color:white;">ERROR EN LA IMPORTACIÓN DEL CSV</label>');
return false;
}
}
});
return false;
}
else{
alert('SELECCIONA UN ARCHIVO CSV PARA IMPORTAR');
return false;
}
});
});
El código php que está al inicio del formulario es porque estoy estableciendo una sesión, ya lo probé sin eso y el error continua.
Agradezco su ayuda....:)
Valora esta pregunta


0