...

View Full Version : jQuery/Ajax - Get the value of a hyperlink.



phantom007
07-29-2008, 08:35 AM
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:


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 (process.php?user=sam)
- John Clinger => jon (process.php?user=jon)
- Patrick Norton => pat (process.php?user=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

Northie
08-19-2008, 02:59 PM
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


<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


$(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)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum