Jump to content

basic ajax get url


PHP_CHILD

Recommended Posts

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..

Link to comment
Share on other sites

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 by abrahamgarcia27
Link to comment
Share on other sites

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 by darrentaytay
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.