Reply to PHP and Ajax

Your name:

Reply:


Posted by jrd100 on 12/04/05 04:51

I am trying to write an web application using AJAX to track what link
the user clicked to leave the website.

The purpose of this is to have the embedded client-side XMLHttpRequest
object call a php script when the user clicks a hyperlink. Then the php
script gets the value from the query string, assigns this value to
variable and updates a MySQL table.

This is not working though. The php script ignores the GET request sent
by the client-side XMLHttpRequest object.

If I call the php script directly by entering a url with parameter from
the browser address bar, the database updates.

I am assuming the reason for failure is once a user leaves the page
where the getHTTPObject was first declared, it is destroyed and
communication with the server is gone.

The below is tested on RedHat 7.3/Apache. The test browser is Firefox
1.5. IE does not currently support a native XMLHttpRequest object as of
yet.

Thanks in advance for any insight.

CODE

*__ajax.html__*

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function getHTTPObject() {
var xmlhttp;
xmlhttp = XMLHttpRequest();
}

http = getHTTPObject();

function phoneHome(obj) {
var x = obj.href;
var url = "yo.php?param="+x;
http.open("GET",url, true);
http.send(null);
}
</script></head>
<body>
<a href="http://yo.com" onClick="phoneHome(this)">yo</a>
<br>
<a href="http://oy.com" onClick="phoneHome(this)">oy</a>
</body></html>

*__yo.php__*

<?php

$link = $_GET['param'];

// assume database connection
$dbh=mysql_connect ("localhost", "<un>", "<pwd>");

mysql_select_db ("<database>");
$query = "insert into sample (idx,link) values('','$link')";
$result = mysql_query($query);

?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация