PHP_CHILD Posted April 3, 2013 Share Posted April 3, 2013 i have a many links like these <a href="www.ex.com/action.php?me=1">member1</a> i wanted to get this by ajax get method.. <script> $("a.member").click(function(e){ $.ajax({ type: "GET", url: "action.php?me=", data: "me=" + me, success: function(data){ alert(data); } }); return false; e.preventDefault(); }); </script> i know somethin wrong here..am in re.php..i am using this to navigate to action.php file.. Any help appreciated.. Quote Link to comment https://forums.phpfreaks.com/topic/276463-basic-ajax-get-url/ Share on other sites More sharing options...
abrahamgarcia27 Posted April 3, 2013 Share Posted April 3, 2013 (edited) I made something not finish, but maybe it can help you. You just need to get the value of the me=1 maybe you can assign an attribute and look for that. <html> <head> <title>Ajax Help</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("a").click(function(event) { event.preventDefault(); $.get("action.php", { me: "1" }, function(data) { $('#log').html(data); }); }); }); </script> </head> <body> <a href="./action.php?me=1" class="member">member1</a> <div id="log"></div> </body> </html> Edited April 3, 2013 by abrahamgarcia27 Quote Link to comment https://forums.phpfreaks.com/topic/276463-basic-ajax-get-url/#findComment-1422601 Share on other sites More sharing options...
darrentaytay Posted April 3, 2013 Share Posted April 3, 2013 (edited) If you need to retrieve the ID, since your using jQuery you can set and get it using .data(). So if you had a list of members like this: <a class="member" data-memberid="1" href="www.ex.com/action.php?me=1">member1</a> <a class="member" data-memberid="2" href="www.ex.com/action.php?me=1">member2</a> <a class="member" data-memberid="3" href="www.ex.com/action.php?me=1">member3</a> You could retrieve the ID for each member and make your AJAX request like this: <script> $("a.member").click(function(e){ var memberID = $(this).data('memberid'); $.ajax({ type: "GET", url: "action.php?me=", data: { me: memberID }, success: function(data){ alert(data); } }); e.preventDefault(); }); </script> Hope that helps. Edited April 3, 2013 by darrentaytay Quote Link to comment https://forums.phpfreaks.com/topic/276463-basic-ajax-get-url/#findComment-1422610 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.