How to call Struts1 Action from Ajax or JavaScript?
- by Dj.
I need to call an action on load of a JSP. To keep track of number of users who visited that page.
I hav an action VisitorCounterAction. Where il update the database.
On load of the JSP im calling an ajax function callCounter();
{
alert("callCounter");
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// i need some correction here
xmlhttp.open("GET",VisitorCounterAction,false);
xmlhttp.send(null);
alert("callCounter returned from Action");
}
I am getting an exception as:
/web/guest/content?p_p_id=31&p_p_lifecycle=0&p_p_state=pop_up&p_p_mode=view&_31_struts_action=%2Fimage_gallery%2Fview_slide_show&_31_folderId=10605 generates exception: null
Please help me with this. Or any other way to call the Action.
I can't reload the page as it'll call onload function again.
Thanks,
Dj