is my first time using AJAX, for more examples that I put into practice, I can not make AJAX send PHP a variable, instead if it communicates with the PHP file, but when I give alert(data);
I get the html from my page .php, instead of showing me the variable that happens as a parameter.
This is the pure AJAX
$.ajax(
{
type: "POST",
url: 'IPE.php',
data: { textValue : textValue }, //intentando pasar textValue que deberia valer 10:10 pero me da el html de ipe.php
success: function(data){
alert(data);//html ipe.php
alert(textValue);//si vale 10:10
}
What is inside this dialog (dialog.js)
$(function () {
$('#myTextBox').mask('00:00');
//Set up the dialog box
$("#myDialog").dialog({
autoOpen: false,
modal: true,
title: "Escriba en formato HH:mm",
buttons: {
'Agregar': function () {
var textValue = $('#myTextBox').val();// valor 10:10
var validTime = textValue.match(/^([0-9]*):[0-5][0-9]$/);
if (!validTime) {
alert('El formato ingresado no es correcto');
} else {
alert(textValue);
$.ajax(
{
type: "POST",
url: 'IPE.php',
data: { textValue : textValue }, //intentando pasar textValue que deberia valer 10:10 pero me da el html de ipe.php
success: function(data){
alert(data);//html ipe.php
alert(textValue);//si vale 10:10
}
});
$(this).dialog('close');
$('#myTextBox').val("");
}
//Now you have the value of the textbox, you can do something with it, maybe an AJAX call to your server!
},
'Cancelar': function () {
$(this).dialog('close');
$('#myTextBox').val("");
}
}
});
//Open the dialog box when the button is clicked.
$('#clickMe').click(function () {
$("#myDialog").dialog("open");
});
});
This is the html
<!DOCTYPE html>
<html>
<head>
<title>IPE (Indisponibilidad de Planta de Emergencia).</title>
<link rel="stylesheet" type="text/css" href="css/estilos.css">
<link href="css/jquery-ui.min.css" rel="stylesheet">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/jquery.mask.js"></script>
<script src="dialogo.js"></script>
</head>
<body>
<div style="left: 82.5%; top:3%; position: absolute;">
<input type="text" id="search" placeholder="Año..">
<div id="myDialog">
<input type="text" id="myTextBox" />
<div id="result"></div>
</div>
<p id="result"></p>
</div>
</body>
</html>
The part of (IPE.php) that must obtain the AJAX data
if(isset($_POST['textValue'])) //
{
$nuevo_registro = $_POST['textValue'];
echo $nuevo_registro;
}
It should be noted that the html is inside IPE.php