I have a HTML link element:
<a href='#' class='editUsrProfile' data-type='text' data-pk='' data-url='file.php'></a>
I set the data-pk
attribute with Jquery:
$('.editUsrProfile').attr('data-pk', usr);
I check with console.log if data-pk
has been set, and it's Ok.
But in my php script, where i check for $_POST['pk']
i get nothing.
Other posts like name etc, that are static works just fine.
So, why can't $_POST
read the attribute set by Jquery, and how can i solve this?
UPDATE
I use "Bootstrap Editable" to send data to php file.
The problem was i enabled editable
before i had set data-pk
.
Simply i changed the events to first set the data-pk
with Jquery.
And then i run the editable
plugin:
$('.editUsrProfile').attr('data-pk', usr);
$('.editUsrProfile').editable({});
As your data-pk
is set on page load the you are initializing editable on page load too. But you are changing data-pk
dynamically so you need to update your params of editable like,
$('.editUsrProfile').editable({
params: function(params) {
params.pk = usr;// or you can try $(this).attr('data-pk') or $('.editUsrProfile').attr('data-pk') whichever works for you
return params;
}
)