bigjo Posted September 3, 2012 Share Posted September 3, 2012 (edited) Hi, I have a html page (build with xml en xsl). I want to update my database when someone visits the page with the date and url page. I want it to be done when someone visits the page. I want to get track on how many times a page has been visited and when. The user don't have to click on anything, it has to be stored when the page is opening. I thought to do it to add a javascript that update the database, but it is not a good idea because javascript is client based. So I thought a could call a jsp file (where the code is written to update the database) when the html page loads.The problem is that I don't know how to call the jsp file, without loading it in the browser. I find something like this: <script language="JavaScript"> function updateStats(){ var jspcall="url.jsp" window.location.href=jspcall } </script> and then I tried with <body onload="updateStats()"> But then ofcourse the page is loaded. Someone an idea how I could do it properly? Edited September 3, 2012 by bigjo 1 Link to comment Share on other sites More sharing options...
smiles Posted September 4, 2012 Share Posted September 4, 2012 (edited) Hi! You should get familiar with AJAX, it is so popular http://w3schools.com...ax_examples.aspAfter understand somehow about it, I recommend jQuery.ajax http://www.w3schools...jquery_ajax.asp Edited September 4, 2012 by smiles Link to comment Share on other sites More sharing options...
Raviteja.Kodati Posted January 11, 2013 Share Posted January 11, 2013 Try this code.. HTML code:<head><script src="hidden.js" type="text/javascript"></script><.head><body onload="create()"></body> Create a java script file and write below script: var xhr;function create(){if(window.XMLHttpRequest)xhr=new XMLHttpRequest();else if(window.ActiveXObject)xhr=new ActiveXObject("Microsoft.XMLHTTP");}add this to d function for action listener.var url="yourown.jsp?num1="+num1.value+"&num2="+num2.value; xhr.open("GET",url,true); xhr.send(null); U can write ur own code in 'yourown' jsp file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now