I have code that relies on jquery that works here:
$(function() {
var referrer = document.referrer;
var dataText = 'client='+client+'&referrer=';
dataText = dataText + referrer;
// Create the AJAX request
$.ajax({
type: "GET",
url: "http://www.myurl.com/project/thecollector.php",
data: dataText,
success: function() {
$('#complete').html( 'Your page view has been added!' );
}
});
});
I have rewritten the code to not need jquery here:
window.addEventListener('domready', function()
{
var referrer = document.referrer;
var dataText = 'client='+client+'&referrer=';
dataText = dataText + referrer;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "http://www.myurl.com/project/thecollector.php?"+dataText;
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
});
The problem I am having is that the jquery code always captures the information to the server I am looking for, but the latter only captures it every once and a while, and it feel seemingly random. Is there any way to have a function call to force it, and I tried onload and it doesn't work either.