I am trying to post data stored in a data-attr to the next page, here is my code
First i add a class and data-attr to all anchor tags like this:
jQuery(\
If I am reading this correctly, you are trying to carry some variable from page to page, when you click an anchor tag.
$.ajax
sends the request to another page without moving to the page. $.ajax
is used a lot for updating or getting data asynchronously, from other places. Without having to refresh the page.
You can store the data-attr in a sessionStorage
variable.
$('body').on('click','a',function(e){
e.preventDefault();
var location = $(this).attr('href');
var data = $(this).attr('data-wptl_ip');
sessionStorage.setItem('wptl_ip', data);
location.href= location;
});
then you can access the data info on the next page with
var myData = sessionStorage.getItem('wptl_ip');
This is assuming you want to move to the next page, along with the data.
Posting to a php file to insert in Database:
$('body').on('click','a',function(e){
e.preventDefault();
var location = $(this).attr('href');
var data = $(this).attr('data-wptl_ip');
$.ajax({
url: 'somePage.php',
data: {someData: data}
}).done(function(response){
sessionStorage.setItem('wptl_ip', data);
location.href= location;
});
});