As you see I've link and attribute so I want to post my attribute with ajax like this:
all attribute value that begins with "data-record-*":
function getContent(par1, data) {
$.ajax({
url: par1,
method: "post",
success: function(data) {
}
});
}
$("a").on("click", () => {
var getLink = $(this).attr("href");
const data = $(this).data();
const postData = {};
Object.keys(data)
.filter(key => key.startsWith("record"))
.forEach(key => {
postData[key.replace("record", "")] = data[key];
});
getContent(getLink, postData);
});
<a href="#" data-record-id="1" data-record-name="section-1">Click on me!</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
if I click anchor all data-record-*
must be post with jquery ajax I want this how to do this ?