Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Need Help with JScript Problem (http.open) to Time a Webpage Read

eze2007eze2007 Posts: 1Member
I am trying to track how long a reader reads a webpage on my site for stastical reasons.

I am trying to build a script that updates the mySQL database with the time duration for reading the page (var milDiff ).


The JS Console doesn't like my http.open('GET' command - keeps denying my persmisson to it I don't know why

Error: uncaught exception: Permission denied to call method XMLHttpRequest.open

All the scripts reside under the same domain name on the same webserver

any advice?

Here is my first attempt at anything remotely AJAX:



Test Page

var startTime = null;
window.onload = function () {
startTime = new Date();
}

window.onunload = function ( ) {
var endTime = new Date();
var milDiff = Math.abs(startTime - endTime);
alert( milDiff );

if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
http = new ActiveXObject("Microsoft.XMLHTTP");
}

http.open('GET', 'http://www.foo.com/path/savetime.php?readTime=' +milDiff, true);

http.onreadystatechange = function() {
if (http.readyState == 4) {
document.getElementById('some_div_id').innerHTML = http.responseText;
}

}
}





Comments

  • CyGuyCyGuy Posts: 312Member
    [b][red]This message was edited by CyGuy at 2006-1-28 16:57:43[/red][/b][hr]
    : I am trying to track how long a reader reads a webpage on my site for stastical reasons.
    :
    : I am trying to build a script that updates the mySQL database with the time duration for reading the page (var milDiff ).
    :
    :
    : The JS Console doesn't like my http.open('GET' command - keeps denying my persmisson to it I don't know why
    :
    : Error: uncaught exception: Permission denied to call method XMLHttpRequest.open
    :
    : All the scripts reside under the same domain name on the same webserver
    :
    : any advice?
    :
    : Here is my first attempt at anything remotely AJAX:
    :
    : [red]<--you will need to specify the type[/red]
    : <head>
    : Test Page
    :
    : var startTime = null;
    : window.onload = function () {
    : startTime = new Date();
    : }
    :
    : window.onunload = function ( ) {
    : var endTime = new Date();
    : var milDiff = Math.abs(startTime - endTime);
    : alert( milDiff );
    :
    : if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    : http = new XMLHttpRequest();
    : } else if (window.ActiveXObject) { // IE
    : http = new ActiveXObject("Microsoft.XMLHTTP");
    : }
    :
    : http.open('GET', 'http://www.foo.com/path/savetime.php?readTime=' +milDiff, true);
    :
    : http.onreadystatechange = function() {
    : if (http.readyState == 4) {
    : document.getElementById('some_div_id').innerHTML = http.responseText;
    : }
    :
    : }
    : }
    :
    :
    :
    :
    :
    :
    [red]a tag may also be used to specify your intended use of the document. you may want to rePost in the ASP or Web Development section of this site, since most of us here focus on browser side scripting[/red]


Sign In or Register to comment.