Good afternoon. I write after reading all the similar cases related to my query in this forum and not finding a solution.
What I need to know is if you can pass the variable from a PHP document to the jQuery code written in another document.
Code example:
File with name "pre_modificar.php" (HTML with JAVASCRIPT)
<html>
<head>
<meta charset="utf-8">
<title>Paso previo a modificar</title>
<script type="text/javascript" src="jquery.tablesorter/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#modificar").attr('disabled', 'disabled');
var consulta;
$("#id").focus();
$("#id").keyup(function(e){
consulta = $("#id").val();
//hace la búsqueda
$("#resultado").delay(100).queue(function(n) {
$("#resultado").html('<img src="imagenes/loading/ajax-loader.gif" />');
$.ajax({
type: "POST",
url: "comprobar.php",
data: "b="+consulta,
dataType: "html",
error: function(){
alert("Error petición ajax");
},
success: function(data){
if (VARIABLE_PHP_QUE_NO_SE_COMO_OBTENER == 0) {
$("#resultado").html(data);
n();
} else {
$("#modificar").removeAttr('disabled');
$("#resultado").html(data);
n();
}
}
});
});
});
});
</script>
</head>
<body>
<form name="seleccionar" action="modificar.php" method="post">
<input type="int" required id="id" name="id" placeholder="Introduce ID..." value="" />
<span id="resultado"></span>
<input type="submit" id="modificar" name="modificar" value="Modificar" /><br><br/>
</form>
</body>
</html>
I have written as VARIABLE_PHP_QUE_NO_SE_COMO_OBTENER the variable that I should get from the PHP document that I detail below.
File with name "check.php" (PHP)
<?php
$user = $_POST['b'];
if(!empty($user)) {
comprobar($user);
}
function comprobar($b) {
include("conexion_db.php");
$query = mysqli_query($conexion, "SELECT * FROM formulario WHERE id = '".$b."'");
$contar = mysqli_num_rows($query);
if($contar == 0){
echo "<span><img src=\"imagenes\web\action_delete.png\"></span>";
}else{
echo "<span><img src=\"imagenes\web\action_check.png\"></span>";
}
}
?>
The variable I want to pass from this PHP document to the first document where the jQuery code is is: $ count
Could you tell me if there is a possible solution to solve this case?
Thank you very much in advance!