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
https://forums.phpfreaks.com/topic/162259-help-with-ajax-promlem-please/
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>

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

 

  • 2 weeks later...

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.