php - Send AJAX request by clicking a link without redirecting user -
i have web application features bunch of different items, generated mysql table. users scroll through it, want them able click link next item insert request mysql database. normally, i’d creating php page (which anyways) grabs item name & user id uri using $_get method & inserts table. however, in case, don’t want users redirected away wherever are. want link send off request, , maybe display small message after successful.
i figured jquery/ajax best this, i’m not familiar it, i’m not sure do. tips appreciated!
you have like
$('.classofyourlink').click(function(e){ e.preventdefault();//in way have no redirect $.post(...);//make ajax call });
in way user makes ajax call clicking link without redirecting. here docs $.post
edit - pass value jquery in case should like
$('.order_this').click(function(e){ e.preventdefault();//in way have no redirect var valuetopass = $(this).text(); var url = "url/to/post/"; $.post(url, { data: valuetopass }, function(data){...} );//make ajax call });
Comments
Post a Comment