I was wondering if and how I can save an HTML5 data-
-attribute directly to my database using PHP?
I have aa button that creates a list item in a <ol>
(ordered list). Within every created list item, I store some information using the HTML5 data-
attribute. Now I would like to save this with PHP to my database.
Is it possible to do that, or should I find another way.
I would recommend you use AJAX.
Using AJAX :
Use a bit of Javascript before you open the PHP file.
You could use something like variable = document.getElementById('IdOfYour<ol>tag').getAttribute('data-something')
to get the contents of your data attribute.
Then you open your PHP file using xmlhttp.open('GET','YourPHPFile.php?dataAttr=' + variable ,false/true')
And in your PHP file you could just use $_GET['dataAttr']
to access the data from your Data Attribute
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.