jQuery .serialize() returning unexpected results when using custom data attributes with forms
I'm trying to debug I'm dealing with I'm having an scenario where using jQuery's `.serialize()` on a form is producing unexpected results when I include custom data attributes... My form has several input fields, but I've also added custom data attributes to some of them to store additional information. When I call `.serialize()`, the custom data attributes are not included in the serialized string, which is causing problems when I try to process the data on the server side. Here's a simplified version of my HTML: ```html <form id="myForm"> <input type="text" name="username" value="testuser" data-role="admin"> <input type="email" name="email" value="test@example.com" data-role="user"> <input type="submit" value="Submit"> </form> ``` And here's the jQuery I'm using to serialize the form: ```javascript $('#myForm').on('submit', function(event) { event.preventDefault(); var serializedData = $(this).serialize(); console.log(serializedData); }); ``` When I submit the form, the output is `username=testuser&email=test%40example.com`, but I need the `data-role` attributes to also be sent with the form data, maybe as part of the serialized string or in a different format. I've tried iterating over the inputs manually and appending the data attributes to the serialized string, but it gets messy and prone to errors. Is there a clean way to include custom data attributes when serializing a form with jQuery, or is there a different approach I should take? Iβm using jQuery version 3.6.0, and Iβm wondering if thereβs a best practice for this kind of scenario. Any insights would be greatly appreciated! Any ideas how to fix this? I'm on Windows 10 using the latest version of Javascript. Any suggestions would be helpful. My development environment is Windows 11. What's the best practice here?