I need to pass JavaScript(jQuery) variable through url, so I can catch it in $_GET with php. Here is what i have tried already:
$(document).ready(function(){
var click=0;
$('#next').click(function(){
var count=$('#next').val();//ovdje imamo koliko je maksimalna proslidjena vrijednost
var data = {};
click++;
if(click>=count){
click=count;
}
data.clicks=click;
window.location.replace('https://www.servis-racunara.net/pages/notifications_page.php?click='+click);
});
});
Doesn't work.
$(document).ready(function () {
var click = 0;
$('#next').click(function () {
var count = $('#next').val();//ovdje imamo koliko je maksimalna proslidjena vrijednost
var data = {};
click++;
if (click >= count) {
click = count;
}
data.clicks = click;
$.get("notifications_page.php",
{ page: clicks },
function () {
});
});
});
Doesn't work.
$(document).ready(function(){
var click=0;
$('#next').click(function(){
var count=$('#next').val();//ovdje imamo koliko je maksimalna proslidjena vrijednost
var data = {};
click++;
if(click>=count){
click=count;
}
data.clicks=click;
$.ajax({
url: "notifications_page.php",
type: "GET",
dataType: "JSON",
data: data,
async: true,
success: function (data) {
}
});
});
});
This works, but strangely. It sends parameter, but I cannot catch it with $_GET in PHP. Please help if you have some idea how to handle this.
UPDATE:
When I look at Inspect tool under Network here is what I see:

Everything works fine but I don't know how to catch this parameter because in my page here is how $_GET looks like:

I think that page should be reloaded in order for $_GET to catch parameter. What do you think?
SECOND UPDATE:
I found a way to put this variable click in url with this:
$(document).ready(function(){
var click=0;
$('#next').click(function(){
var count=$('#next').val();//ovdje imamo koliko je maksimalna proslidjena vrijednost
click++;
if(click>=count){
click=count;
}
$('a').attr('href','?id='+click);
});
});
This last line does it all. But now my counter doesn't work, due to reloading of page(href attribute). Can you please help me now just to fix that?
notifications_page.php?