Reputation: 1347
I'm getting this error but i can't see what is wrong. I need a little help. I've tried everything: looked for illegal characters, erasing the semi colon but i can't fix it anyway.
(function(){
$.ajax({
dataType: "json",
url: "prueba.php",
type: "get",
data: "t=javascript",
success:function(inf){
var div += "<span class='carpeta'>";//<-- here is where the error comes but i dont see anything!
div =+ "<span class='titulo'>"+inf["categoria"]+"<h2>"+inf["titulo"]+"</h2></span>";//cerrando titulo
div =+"<span class='mascara'>";
div =+"<h2>"+inf["titulo"]+"</h2>";
div =+ "<p>"+info["descripcion"]+"</p>";
div =+ "<a onclick('tutorial_numero("+1+")') href='javascript:void(0)'>Leer mas</a>";
div =+"</span>"; //cerrando el span de la class mascara
div =+ "</span>";//cerrando el span de la class carpeta
document.getElementById("contenido").innerHTML = "porque tio";
alert("ola k ase")
}
});
})();
the php code
<?php
if(isset($_GET["t"]))
{
require 'conexion.php';
$getConexion = new conexion();
$conexion_mysql = $getConexion->mysql();
$id_tutorial = $_GET["t"];$query = "SELECT titulo,contenido_tutorial,descripcion,categoria FROM tituriales WHERE tags LIKE '%$id_tutorial%'";
$ejecutar_query = $conexion_mysql->prepare($query);
$ejecutar_query->execute();
$enviar = $ejecutar_query->fetchAll(PDO::FETCH_ASSOC);
foreach($enviar as $resultado)
{
$f['titulo'] = $resultado['titulo'];
$f['contenido'] = $resultado['contenido_tutorial'];
$f['descripcion'] = $resultado['descripcion'];
if($resultado['categoria']=="web");
{
$f['categoria'] = "<img src='../pc.png' />";
}
if($resultado['categoria']=="desktop")
{
$f['categoria'] = "@";
}
if($resultado['categoria']=="ambos")
{
$f['categoria'] = "klk";
}
//echo $f["categoria"];
echo json_encode($f);
}
}
?>
Upvotes: 0
Views: 476
Reputation: 3821
Shane Andrade already gave you one part of your answer, but that doesn't actually fix the error you get first:
var div += "<span class='carpeta'>";
This line is invalid all on its own, no other code necessary to see that. div
is not defined yet, but you try to add something to it, since div += x
is just shorthand for div = div + x
. Just assign the string here:
var div = "<span class='carpeta'>";
Upvotes: 2
Reputation: 664538
Your assignment operators are wrong:
=
+=
instead of =+
Upvotes: 2
Reputation: 2675
Your string concatenation operators aren't correct. Replace =+
with +=
(function(){
$.ajax({
dataType: "json",
url: "prueba.php",
type: "get",
data: "t=javascript",
success:function(inf){
var div += "<span class='carpeta'>";//<-- here is where the error comes but i dont see anything!
div += "<span class='titulo'>"+inf["categoria"]+"<h2>"+inf["titulo"]+"</h2></span>";//cerrando titulo
div +="<span class='mascara'>";
div +="<h2>"+inf["titulo"]+"</h2>";
div += "<p>"+info["descripcion"]+"</p>";
div += "<a onclick('tutorial_numero("+1+")') href='javascript:void(0)'>Leer mas</a>";
div +="</span>"; //cerrando el span de la class mascara
div += "</span>";//cerrando el span de la class carpeta
document.getElementById("contenido").innerHTML = div;
}
});
})();
Upvotes: 3
Reputation: 1300
It looks like PHP doesn't return json. I think you should debug PHP script.
Upvotes: 0