I am still new to PHP and AJAX but I think I have some grasp about JavaScript and jQuery. Here is my problem: In my UI I have a form input field and an OK-button (which is not part of the form). Everytime the user clicks the ok-button, the content of the input field plus some session variables shall be sent to the server via AJAX, so that the page does not have to reload.
Here is my js-Code:
$.post('api/someFile.php',
{
var1: nr1,
var2: nr3,
var3: nr3,
}
);
Here is my php-Code someFile.php
:
<?php
// activate current session
session_start();
// use php console for debugging
require_once('PhpConsole.php');
PhpConsole::start();
// get data from UI
$var1 = $_POST["var1"];
$var2 = $_POST["var2"];
$var3 = $_POST["var3"];
debug("start receiving");
debug($var1 . " " . $var2 . " " . $var3);
// ... proceed with the data and write it in database...
debug("finished");
?>
The problem is that all the code in someFile.php
is executed twice. This is the console output:
javascript debug: send to server: nr1, nr2, nr3
php debug: start receiving
php debug: nr1 nr2 nr3
php debug: finished
php debug: start receiving
php debug: nr1 nr2 nr3
php debug: finished
However, the data gets written in the database only once. That is quite weird. Is that a bug in the php console or is my code bad?