Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <?
  2.  
  3.  
  4. if(isset($_GET['name'])) {
  5. /*Some queries if need*/
  6. echo '{"name":"'.$_GET['name'].'"}';
  7. }
  8. else {
  9.  
  10. $bd_host='localhost';
  11. $bd_user='root';
  12. $bd_password='';
  13. $bd_base='db_name';
  14.  
  15. /*connect to db*/
  16. $con=mysql_connect($bd_host, $bd_user, $bd_password);
  17.  
  18. /*control connection*/
  19. if(!con) {
  20. echo 'Error.';
  21. exit;
  22. }
  23.  
  24. /*select databese name*/
  25. mysql_select_db($bd_base, $con);
  26.  
  27. /*set encode to utf-8*/
  28. mysql_query('SET NAMES utf8');
  29.  
  30.  
  31.  
  32. $sql="Select name from users limit 10"
  33. $res=mysql_query($sql);
  34. ?>
  35. <ul>
  36. <?
  37. While($row=mysql_fetch_assoc($res)) { ?>
  38. <li onclick="ajax('<? echo $row['name']; ?>');return false;"><? echo $row['name']; ?></li>
  39. <?
  40. }
  41. ?>
  42. </ul>
  43. <?
  44. }
  45. ?>
  46.  
  47. <script>
  48. function ajax(name) {
  49. var url='/text.php?name='+name;
  50.  
  51. if (window.XMLHttpRequest) {
  52. xmlhttp = new XMLHttpRequest();
  53. } else if (window.ActiveXObject) {
  54. xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  55. }
  56. xmlhttp.open('GET', url, true);
  57.  
  58. xmlhttp.onreadystatechange = function() {
  59. if (xmlhttp.readyState == 4) {
  60. myfunction(xmlhttp.responseText);
  61. }
  62. }
  63.  
  64. xmlhttp.send(null );
  65.  
  66.  
  67. function myfunction(response) {
  68. var= arr;
  69. arr = JSON.parse(response);
  70. alert (arr.name);
  71. }
  72.  
  73. }
  74. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement