Jump to content

Help with ajax promlem please


richarro1234

Recommended Posts

Hello,

 

Im trying to setup a page where people can accept requests without having the page refresh, but i need to send the external page 2 variables from the first page, but for some reason it doesnt work, it works fine if i try to send 1, but not 2.

 

Can someone please help me try to sort this out, here is the code:

<script type="text/javascript">
$(function() {


$(".addfriend").click(function(){

//Save the link in a variable called element
var element = $(this);

//Find the id of the link that was clicked
var add_id = element.attr("myid");
var addf_id = element.attr("friendsid");

//Built a url to send
var info = 'myid=' + add_id, '&friendid=' + addf_id;
if(confirm("This will add this person as a friend!"))
	  {
$.ajax({
   type: "GET",
   url: "inc/addfriend.php",
   data: info,
   success: function(){
   
   }
});
         $(this).parents(".record").animate({ backgroundColor: "#000000" }, "fast")
	.animate({ opacity: "hide" }, "normal");

}

return false;

});

});
</script>

 

I have also tried this line:

var info = 'myid=' + add_id, '&friendid=' + addf_id;

 

Like this:

var info = 'myid=' + add_id '&friendid=' + addf_id;

 

but it still didnt work.

 

Anyone know how to fix this?

 

Thanks

Rich

Link to comment
Share on other sites

try this:

<script type="text/javascript">
$(function() {
  $(".addfriend").click(function(){
    if(confirm("This will add this person as a friend!")){
      //Built data to send
      var data = {
        'myid' : $(this).attr('myid'),
        'friendid' : $(this).attr('friendsid')
      };
      $.ajax({
        type: 'GET',
        url: 'inc/addfriend.php',
        data: data,
        success: function(){
          $(this).parents('.record').animate({ backgroundColor: "#000000" }, "fast")
          .animate({ opacity: "hide" }, "normal");
        }
      });
    }
    return false;
  });
});
</script>

Link to comment
Share on other sites

Thanks, that worked fine,

 

EDIT: i fixed the PHP bit.

 

it also doesnt fade out after clicking on the link.

$.ajax({
        type: 'GET',
        url: 'addfriend.php',
        data: data,
        success: function(){
          $(this).parents('.record').animate({ backgroundColor: "#000000" }, "fast")
          .animate({ opacity: "hide" }, "normal");
        }
      });

 

Thanks

Rich

 

Link to comment
Share on other sites

  • 2 weeks later...
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.