Created
August 18, 2011 21:52
-
-
Save DemitryT/1155339 to your computer and use it in GitHub Desktop.
AJAX feature to retrieve user information (from my personal website, which I'm writing in PHP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(document).ready(function() | |
| { | |
| var hideDelay = 500; | |
| var userID; | |
| var hideTimer = null; | |
| // One instance that's reused to show info for the current person | |
| var container = jQuery('<div id="personPopupContainer">' | |
| + '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="personPopupPopup">' | |
| + '<tr>' | |
| + ' <td class="corner topLeft"></td>' | |
| + ' <td class="top"></td>' | |
| + ' <td class="corner topRight"></td>' | |
| + '</tr>' | |
| + '<tr>' | |
| + ' <td class="left"> </td>' | |
| + ' <td><div id="personPopupContent"></div></td>' | |
| + ' <td class="right"> </td>' | |
| + '</tr>' | |
| + '<tr>' | |
| + ' <td class="corner bottomLeft"> </td>' | |
| + ' <td class="bottom"> </td>' | |
| + ' <td class="corner bottomRight"></td>' | |
| + '</tr>' | |
| + '</table>' | |
| + '</div>'); | |
| jQuery('body').append(container); | |
| jQuery('.personPopupTrigger').live('click', function() | |
| { | |
| // format of 'rel' tag: userId from Books table | |
| //var settings = jQuery(this).attr('rel'); | |
| userID = jQuery(this).attr('rel'); | |
| // If no id in url rel tag, don't popup blank | |
| if (userID == '') | |
| return; | |
| if (hideTimer) | |
| clearTimeout(hideTimer); | |
| var pos = jQuery(this).offset(); | |
| var width = jQuery(this).width(); | |
| container.css({ | |
| left: (pos.left + width + 35) + 'px', | |
| top: pos.top - 15 + 'px' | |
| }); | |
| jQuery.ajax({ | |
| type: 'GET', | |
| cache: false, | |
| //dataType: (jQuery.browser.msie) ? "text" : "xml", | |
| url: 'sellerinfo.php', | |
| data: "userID=" + userID, | |
| success: function(data) | |
| { | |
| // Verify requested person is this person since we could have multiple ajax | |
| // requests out if the server is taking a while. | |
| if (userID > 0) | |
| { | |
| jQuery('#personPopupContent').html('<span style="line-height: 1em;">' + data + '</span>'); | |
| } | |
| } | |
| }); | |
| container.css('display', 'block'); | |
| }); | |
| jQuery('.personPopupTrigger').live('mouseout', function() | |
| { | |
| if (hideTimer) | |
| clearTimeout(hideTimer); | |
| hideTimer = setTimeout(function() | |
| { | |
| container.css('display', 'none'); | |
| }, hideDelay); | |
| }); | |
| // Allow mouse over of details without hiding details | |
| jQuery('#personPopupContainer').mouseover(function() | |
| { | |
| if (hideTimer) | |
| clearTimeout(hideTimer); | |
| }); | |
| // Hide after mouseout | |
| jQuery('#personPopupContainer').mouseout(function() | |
| { | |
| if (hideTimer) | |
| clearTimeout(hideTimer); | |
| hideTimer = setTimeout(function() | |
| { | |
| container.css('display', 'none'); | |
| }, hideDelay); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a class='personPopupTrigger' id='sellerinformation' rel='".$userId."'> | |
| Seller Info | |
| </a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $userID = $_GET['userID']; | |
| // connection settings stored in file | |
| include("connectionParameters.php"); | |
| $connection = mysql_connect($host,$user,$pass) | |
| or die ("We're sorry, there seems to be an error. Please try again later."); | |
| mysql_select_db($database); | |
| $sql="SELECT * FROM Users WHERE userId = '.$userID.'"; | |
| $result = mysql_query($sql); | |
| while($row = mysql_fetch_array($result)) | |
| { | |
| echo "<div id='personPopupContent'>"; | |
| echo "<p style='font-size: 12px;'><b>First name:</b> ".$row["firstName"]."</p>"; | |
| //echo "<br/>"; | |
| echo "<p style='font-size: 12px;'><b>School:</b> ".$row["university"]."</p>"; | |
| //echo "<br/>"; | |
| if($row["phone"] == ""){ | |
| echo "";} | |
| else{ | |
| echo "<p style='font-size: 12px;'><b>Phone:</b> ".$row["phone"]."</p>"; | |
| //echo "<br/>"; | |
| } | |
| echo "<div style='font-size: 12px; width: 175px;'><b>Email:</b><span style='width: 170px;'> ".$row["email"]."</span></div>"; | |
| echo "</div>"; | |
| } | |
| mysql_close($con); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment