Mjukis Mjukis - 1 year ago 66
Javascript Question

$_POST won't fetch attribute set by jquery

I have a HTML link element:

<a href='#' class='editUsrProfile' data-type='text' data-pk='' data-url='file.php'></a>

I set the
attribute with Jquery:

$('.editUsrProfile').attr('data-pk', usr);

I check with console.log if
has been set, and it's Ok.

But in my php script, where i check for
i get nothing.

Other posts like name etc, that are static works just fine.

So, why can't
read the attribute set by Jquery, and how can i solve this?


I use "Bootstrap Editable" to send data to php file.

The problem was i enabled
before i had set

Simply i changed the events to first set the
with Jquery.

And then i run the

$('.editUsrProfile').attr('data-pk', usr);

Answer Source

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,

    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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download