9 Replies - 1101 Views - Last Post: 17 July 2011 - 04:50 PM

#1 britblad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-July 11

I need help writing the java part of a facebook like friends request

Posted 16 July 2011 - 01:24 PM

i have a social net work that i am building what i want to do is use jquery to update my Icon when i get a friend request

I have the PHP function written i just need help with the jquery part if anyone can help me.

I know this will be the first question so YES i have wasted hours on google looking for the answer!
Is This A Good Question/Topic? 0
  • +

Replies To: I need help writing the java part of a facebook like friends request

#2 maniacalsounds   User is offline

  • D.I.C Regular
  • member icon

Reputation: 118
  • View blog
  • Posts: 474
  • Joined: 27-June 10

Re: I need help writing the java part of a facebook like friends request

Posted 16 July 2011 - 01:42 PM

Since you have the PHP script down, simply use AJAX. If you want to do it via jQuery, you will use $.ajax();

Documentation:
http://api.jquery.com/category/ajax/

Use the AJAX to call the script, which will update the icon :)
Was This Post Helpful? 1
  • +
  • -

#3 britblad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-July 11

Re: I need help writing the java part of a facebook like friends request

Posted 16 July 2011 - 08:35 PM

wow now if i just knew how to use ajax with jquery i would be set!
Was This Post Helpful? 0
  • +
  • -

#4 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: I need help writing the java part of a facebook like friends request

Posted 17 July 2011 - 06:43 AM

The link maniacalsounds provided does show how to use AJAX with jQuery. Generally it is in this format:
 $.ajax({
    type:"POST",
    url:"my_url.php",
    data:"my_data",
    success:function(data){
        //do something with the data returned
    }

  });


What does your PHP script look like?
Was This Post Helpful? 0
  • +
  • -

#5 britblad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-July 11

Re: I need help writing the java part of a facebook like friends request

Posted 17 July 2011 - 07:48 AM

$query = $this->db->where('mem2',$id)->get('friend_requests');
		if($this->db->num_rows() >= 1){
			
			$requestId = $this->db->num_rows();
		}else{
			
			$requestId = 0;
		}			
		
		return $requestId;

i use codeigniter framework so it may look a bit wierd to you but the first line is a Database call and the rest is easy enugfh to read.

where your reply says mydata is mydata the returned var?

This post has been edited by britblad: 17 July 2011 - 07:50 AM

Was This Post Helpful? 0
  • +
  • -

#6 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: I need help writing the java part of a facebook like friends request

Posted 17 July 2011 - 12:34 PM

Hi,
No, what is returned is what the parameter for the anonymous function declared upon success, the line:
 success:function(data)


data is what is returned from the AJAX call.

You would just need to make sure the result is actually output from the ajax file, in the form of an echo or the like. I prefer to use JSON as the data type when I do AJAX calls. The PHP function json_encode is useful when returning data as JSON.
Was This Post Helpful? 0
  • +
  • -

#7 britblad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-July 11

Re: I need help writing the java part of a facebook like friends request

Posted 17 July 2011 - 01:56 PM

wait so i can just do a json_endode(var) and it will send it mabey thats my problem i was trying to echo the json_encode(var) i will give that a try before i revert back to pure php and have it work on refresh. Here i tought i had some dumb error in my php thx for the info im gona try this then if it dont work im gona try to do it via strait php and make sure that works first b4 i start tring things im not use to doing.

still cant seem to get it to work gona try the pure php aproach for now then once that works edit the code so it will work with jquery

thx for trying to help!
Was This Post Helpful? 0
  • +
  • -

#8 britblad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-July 11

Re: I need help writing the java part of a facebook like friends request

Posted 17 July 2011 - 02:11 PM

Want a good laugh? My problem with my scrips crashing wasn't becuse of my php or the json it was because i forgot a }


wow i cant believe that

my code still isnt working right tho gona post the java/jquery

function friendRequest(){
	var base_url = '<?php echo base_url();?>';
	$.ajax({
    url: base_url + 'site/check_num_friends/',
    type: 'POST',
    data: 'my_data',
    dataType: 'json',
    timeout: 8000,
    success: success_function
  });

  function success_function(json) {
    
	if (json.arr > 0)
	  $('#myImage').attr('src', $('#myImage').attr('src').replace(/no_/, 'yes_'));
	 
  }  
}	

Was This Post Helpful? 0
  • +
  • -

#9 Jstall   User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: I need help writing the java part of a facebook like friends request

Posted 17 July 2011 - 04:27 PM

Hi,


You should still echo the data you are returning.

You should use firebug or something similar to help see what is being sent and returned from your AJAX calls, it tends to make things easier.

What exactly is happening with your above code?

Oh and on a side note you are doing Javascript, Java is a totally different language :).
Was This Post Helpful? 0
  • +
  • -

#10 britblad   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 16-July 11

Re: I need help writing the java part of a facebook like friends request

Posted 17 July 2011 - 04:50 PM

I forgot about firebug thx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1