I want to run an ajax function when I click on bootstrap tab.
I have html:
<li><a href="#upotrebljeni" data-toggle="tab">Upotrebljeni resursi</a></li>
jquery ajax function:
$('a #upotrebljeni').click(function (e) {
var ajdi = '22';
var radnici = 'radnici';
var prvi = '1';
$.ajax({
url: 'getRMZ.php', // make this url point to the data file
dataType: 'json',
data:{id_akt:ajdi, tabela:radnici, prvi:prvi},
async: false,
type: 'POST',
success:function(data){
console.log(data);
},
error:function(data) {
console.log(data);
}
});
});
and getRMZ.php pdo file:
try {
/* Establish the database connection */
$conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $conn->query("SELECT id_tabele,naziv FROM track_aktivnosti WHERE prvi = :prvi AND id_akt = :id_akt AND tabela = :tabela");
$result->execute(array(':prvi' => $_POST['prvi'], ':id_akt' => $_POST['id_akt'], ':tabela' => $_POST['tabela']));
$jsonTable = json_encode($result);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo $jsonTable;
Now when I click on tab a #upotrebljeni I dont get any action, any error, nothing ... What can be a problem here?
UPDATE: I via ajax get an error: "ERROR: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':prvi AND id_akt = :id_akt AND tabela = :tabela' at line 1"