Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    907
    Thanks
    301
    Thanked 2 Times in 2 Posts

    Question jQuery/Ajax - Get the value of a hyperlink.

    Hi All,

    I have a search user option on my webpage (search.php) where people can search for a product. The processing part is done on a separate php page (process.php)


    The code for process.php page is:
    Code:
    	if($_GET['action']=='search_user'){
    	$name = $_GET['txtnamesearch'];
    	$result = mysql_query("select username,full_name from login where username LIKE'$name%' or full_name LIKE'$name%'");
    	$num_rows = count($result);
    		if($num_rows<1)
    		echo "<B>Oouchhh!! Try refining your search.</b>";
    		else{
    			for($x=0;$x<$num_rows;$x++){
    			echo '- '.$result[$x]['full_name'] .' => <a id='.$result[$x]['username'].'>'. $result[$x]['username']. '</a><BR>';
    			}
    		}
    	}//End Search User


    The result on the search.php page will output as the following :

    Search Results:
    - Sam Thomas => sam
    - John Clinger => jon
    - Patrick Norton => pat


    Now, I want such that clicking on each username would display their profile details.

    What ajax call do I have to make and how?


    Thanx

  • #2
    New Coder
    Join Date
    Aug 2008
    Location
    Yorkshire, England
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post
    It depends where you want to display it, and where/how that content gets generated

    Personally I'd make the links real, with an href set to the page that would display the profile (based on id, or something like that). then five them a class, or the parent element an id or something so that they can be identified.

    Then you need a container to put the ajaxed content into

    eg

    Code:
    <b>Search Results:</b><br>
    - Sam Thomas =&gt; <a class='ajax' href=process.php?user=sam" target="_blank">sam</a><br>
    - John Clinger =&gt; <a class='ajax' href="process.php?user=jon" target="_blank">jon</a><br>
    - Patrick Norton =&gt; <a  class='ajax' href="process.php?user=pat" target="_blank">pat</a><br>
    <div id='profile'>
    <!-- ajaxed profile content gets put in here -->
    </div>
    then you can use jquery's 'load' function

    Code:
    $(function() {
    	$("a.ajax").click(function() {
    		$("div#profile").empty().load($(this).attr('href'));
    		return false;
    	});
    });
    This isn't real AJAX as it doesn't use XML, it's more asynchronous http and HTML (AHAH)
    Last edited by Northie; 08-19-2008 at 02:01 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •