php - display data via ajax when using $_GET -
how display data based on `$_get', without refreshing page ?
i have example, , shows correct result whenever click add
(increments 1), of course first refreshes page.
how make same thing without visible page refresh, using ajax?
php , html
if (isset($_get['add'])) { $_session['numbers']++; } echo $_session['numbers']; ?> <br> <a href="test.php?add" class="add">add</a> <div id="response"></div>
and if example wanted pull database via post
, print it, this:
$.post('print_something.php', function(response) { $('#response').html(response); });
but how change get, since there stuff in url plus sessions?
edit:
i tried this, removed php current script, added get.php
this:
session_start(); if (isset($_get['add'])) { $_session['numbers']++; } echo $_session['numbers'];
and inside main index
script have this:
$('a.add').click(function() { $.get('get.php', function(response) { $('#response').html(response); }); return false; });
now not increment each time click add
, shows 1
first time , doesn't change afterwards.
you not passing add
parameter $.get
, isset($_get['add'])
false. add add
ajax call
$.get('get.php', {add:true}, function(response) { $('#response').html(response); });
i put {add:true}
, true
anything, checking if set, not value
alternatively, add url
$.get('get.php?add=true', function(response) { $('#response').html(response); });
Comments
Post a Comment