How To Pass Dynamic Data From Html Data-attribute To A Query Using Javascript?
Edit:
It seems in your case, that you would rather have the button perform a normal post and render the entire page again with the modal, and new conversations?
If so, then you can put all your data in a html form:
<formmethod="post"><inputname="empproj_id"value="<?=$employeeproject['emproj_id'];?>">
...
<buttontype="submit"></form><!--Insert Modal Code here-->
Solution 2:
You should send data from html to php. Since html running on client side (in the browser) and php file executing on server side.
PHP manual: http://php.net/manual/en/reserved.variables.get.phphttp://php.net/manual/en/reserved.variables.post.php
Simplest way, using jQuery:
<buttonid='buttonWithData' {data-attributes}></button><scripttype='text/javascript'>var data = $('#buttonWithData').data();
$.ajax('urlOfYoursPhpFile', {
async: false,
data: data
});
</script>
You can then catch data in your php file using GET
array.
Beware of SqlInjection working with GET and POST arrays.
Solution 3:
Use jquery selectors to get the data from the attributes and then send it throught ajax.var dataarray += $("button").attr ("data-...")
get all the data in an array or variables and then $.ajax ({ data: {"attrdata" : dataarray} , type: "POST",target="callback.php", sucess: function (data){ $("#modal").html(data);} });
Post a Comment for "How To Pass Dynamic Data From Html Data-attribute To A Query Using Javascript?"