I have this problem.. I want to edit a row using ajax to send data to SQL 2005 and the response is a JSON object with slashes. The jQuery Insert and delete good but when i use JSON for getting rows it doesn`t work
Here's the error:
Here's the PHP code: preins.php
if(isset($_POST['editvalue']))
{
$query_ed = "SELECT dbo.alumno.alumnoID, dbo.alumno.nombre,
dbo.alumno.apaterno, dbo.alumno.amaterno,
CONVERT(VARCHAR, dbo.alumno.dateReg, 103) as dateReg,
dbo.alumno.IDPeriodo
FROM dbo.alumno
WHERE dbo.alumno.alumnoID= '{$_POST['id']}'";
$sql_ed = sqlsrv_query($conn,$query_ed);
if( $sql_ed === false ) {
die( print_r( sqlsrv_errors(), true));
}
$obj_ed = sqlsrv_fetch_object($sql_ed);
header("Content-type: text/x-json");
// $obj_ed = stripslashes($obj_ed);
//$obj_ed= mysql_real_escape_string($obj_ed);
echo json_encode($obj_ed);
// echo json_encode($obj_ed, JSON_UNESCAPED_SLASHES), "\n";
exit();
}
Here's the AJAX:
jQuery(document).on("click", ".open-edit", function ()
{
jQuery('#save').hide();
jQuery('#update').show();
var IdEdit = jQuery(this).data('id');
/*return false;*/
jQuery.ajax({
url : "preins.php",
type : "POST",//url:'buscar.php?act=insertar',
datatype: "JSON",
data : {
editvalue : 1,
id : IdEdit
},
success:function(show)
{
// alert("Success AJAX: "+JSON.stringify(show)); // Read JSON
// jQuery('.modal-body #save').hide();
jQuery('.modal-body #update').show();
jQuery('.modal-body #txtida').attr('disabled',true);
jQuery('.modal-body #txtFecha_Pre_Inse').attr('disabled', true);
jQuery('.modal-body #txt_IDPeriodo').attr('disabled', true);
jQuery('.modal-body #id').val(show.alumnoID);
jQuery('.modal-body #txtida').val(show.alumnoID);
jQuery('.modal-body #txtnoma').val(show.nombre);
jQuery('.modal-body #txtapa').val(show.apaterno);
jQuery('.modal-body #txtama').val(show.amaterno);
jQuery('.modal-body #txtFecha_Pre_Inse').val(show.dateReg);
jQuery('.modal-body #txt_IDPeriodo').val(show.IDPeriodo);
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
//return false;
});
Aucun commentaire:
Enregistrer un commentaire