I've researched about this issue (I read a lot of StackOverflow questions) and I still can't figure out a solution.
I get the id HTML 'a' attribute value with jQuery when I click the link and then I need send it to a php file which will do a database query. I tried by using $.ajax
and $.post
jQuery functions and I get the same error.
With $.post
var idElement;
$(document).ready(function(){
$('.linkElement').click(function(){
idElement= $(this).attr('id');
console.log(idElement); // Shows id value on console
$.post("showElement.php", idElement).done(function (){
alert("All went good");
});
$(document.body).load("showElement.php");
});
});
With $.ajax
var idElement;
$(document).ready(function(){
$('.linkElement').click(function(){
idElement= $(this).attr('id');
console.log(idElement); // Shows id value on console
$.post("showElement.php", idElement).done(function (){
alert("All went good");
});
$.ajax({
url: "showElement.php",
type: "POST",
data: {'idElement':idElement}
});
});
});
When I use $_POST['idElement']
in my showElement.php
file I get the following:
Notice: Undefined index: idElement in C:\xampp\htdocs\path\to\showElement.php on line 28
What am I doing wrong?
EDIT: I tested this with Firebug and it says it's ok. And data shown in Firebug Console appears correctly, but PHP file is not shown in browser (var_dump returns values it should have).
Any idea about this?