[jQuery] Cannot Get JQuery Ajax to work in Google Chrome browser
I have a piece of code that updates a script with the page scroll and
time on page when the user closes the page. I have this working in
Firefox and IE, but it will not work in Chrome. Chrome will calculate
the values correctly, but it will not post to the script. I have
narrowed down the problem to being in the JQuery call to the ajax
function. Does anyone know what I am doing wrong here?
var maxScroll = 0;
var pageOpen = new Date();
var currentURL = window.location;
var updateURL = "/wp-content/plugins/extra-tracking/update.php";
var intervalUpdate = false;
if (intervalUpdate) {
setInterval( update, 15000);
}
jQuery(window).scroll(function(){
scrollPercent = Math.floor(jQuery(window).scrollTop() / ( jQuery
(document).height() - jQuery(window).height() ) * 100 );
if (scrollPercent > maxScroll) {
maxScroll = scrollPercent;
}
});
function update() {
time = pageTime();
temp = jQuery.ajax({
type: "POST",
url: updateURL,
data: "pageScroll="+maxScroll+"&pageTime="+time
+"&location="+currentURL
//success: function(msg){ alert("Page time: " + time + " Page
Scroll " + maxScroll); }
});
return false;
}
function pageTime() {
curTime = new Date();
minutes = (curTime.getMinutes() - pageOpen.getMinutes());
seconds = (curTime.getSeconds() - pageOpen.getSeconds());
time = (seconds + (minutes * 60));
if (time < 0) { time = 0; }
return time;
}
jQuery(window).unload( function ()
{
endTime = pageTime();
temp = jQuery.ajax({
type: "POST",
url: updateURL,
data: "pageScroll="+maxScroll+"&pageTime="+endTime
+"&location="+currentURL
//success: function(msg){ alert("Page time: " + time + " Page
Scroll " + maxScroll); }
//error: function (xhr, desc, exceptionobj) { alert
(xhr.responseText); }
});
} );