Good! I tell you my problem.
I make a request to a php file with AJAX, in this file I bring a long text from my database (mysql) and I save it in a php array, then I pass it to js with json_encode ();
The problem I have is that there are times when the text shows it well, other times it shows nothing, it says empty ... I suspect that is when several special characters come together ... the strange thing is that when I had my page on a local server with xampp this did not happen, the problem started when I uploaded a free hosting. the error that appears to me is "json parse error", search in google, I read many pages and I could not solve the error! I leave the php and ajax caught.
the php one:
$sql = "SELECT descripcion FROM localidades WHERE id_localidad='$id'";
$rs = mysql_query($sql);
if(mysql_num_rows($rs)>0){
while($fila=mysql_fetch_array($rs)){
//son los campos
$arr = array('descripcion'=>$fila[0],
'success'=>true);
//$arr = array('descripcion'=> str_replace("\r\n", "\n", $fila[8]), 'success'=>true);
}
}else{
$arr = array('success'=>false);
}
echo json_encode($arr);
and this is the ajax with the request:
jQuery.ajax({
type:"POST",
data:{param: id,
param2:"descripcion"},
url: "scripts/buscar_loc2.php",
dataType:'json',
success: function(r){
// var desc = eval ('(' + r.descripcion + ')');
jQuery("#loc_desc").val(r.descripcion);
//alert(desc);
},error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
});
Thank you very much and I hope I can solve this problem!