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
https://forums.phpfreaks.com/topic/276463-basic-ajax-get-url/
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>

Link to comment
https://forums.phpfreaks.com/topic/276463-basic-ajax-get-url/#findComment-1422601
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.

Link to comment
https://forums.phpfreaks.com/topic/276463-basic-ajax-get-url/#findComment-1422610
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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