Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- if(isset($_GET['name'])) {
- /*Some queries if need*/
- echo '{"name":"'.$_GET['name'].'"}';
- }
- else {
- $bd_host='localhost';
- $bd_user='root';
- $bd_password='';
- $bd_base='db_name';
- /*connect to db*/
- $con=mysql_connect($bd_host, $bd_user, $bd_password);
- /*control connection*/
- if(!con) {
- echo 'Error.';
- exit;
- }
- /*select databese name*/
- mysql_select_db($bd_base, $con);
- /*set encode to utf-8*/
- mysql_query('SET NAMES utf8');
- $sql="Select name from users limit 10"
- $res=mysql_query($sql);
- ?>
- <ul>
- <?
- While($row=mysql_fetch_assoc($res)) { ?>
- <li onclick="ajax('<? echo $row['name']; ?>');return false;"><? echo $row['name']; ?></li>
- <?
- }
- ?>
- </ul>
- <?
- }
- ?>
- <script>
- function ajax(name) {
- var url='/text.php?name='+name;
- if (window.XMLHttpRequest) {
- xmlhttp = new XMLHttpRequest();
- } else if (window.ActiveXObject) {
- xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
- }
- xmlhttp.open('GET', url, true);
- xmlhttp.onreadystatechange = function() {
- if (xmlhttp.readyState == 4) {
- myfunction(xmlhttp.responseText);
- }
- }
- xmlhttp.send(null );
- function myfunction(response) {
- var= arr;
- arr = JSON.parse(response);
- alert (arr.name);
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement