Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Stored Proc from a JavaScript Event

Status
Not open for further replies.

MxLover

Programmer
Oct 15, 2002
2
0
0
US
I am integrating a 3rd party OLAP tool (Java Applet) into our Cold Fusion app. I need a way of logging what users are doing in the Java applet. I have access to it's events and methods via JavaScript.

We want to log what widgets in the applet the users are clicking on. When the event fires, we want to run a stored proc that logs the event.

My question is . . .
Is there a way to call a cfm template that just fires a stored procedure without displaying any output. I don't want to display a new browser window, or change what's on the current page.

My gut tells me that this is impossible, but there must be workarounds.

 
How are you intending to trigger the stored procedure? Is it by an event like on click or on leaving a field in the form? If it is, you can pass all the values to the page with the stored procedure via form fields using hidden inputs, run the procedure and pass all the original values back plus any new ones in a form again using hidden inputs. Use JavaScript at the end of the procedure page to pass the data back automatically.

Your hidden inputs passed over will look like this:

<form name=&quot;frmRunProc&quot; action=&quot;proc.cfm&quot; method=&quot;POST&quot;>
<!--- here a button is used to trigger the event --->
<input type=&quot;input&quot; name=&quot;gotoproc&quot; value=&quot;Submit&quot;
onclick=&quot;javascript:document.frmRunProc.submit()&quot;>
<input type=&quot;hidden&quot; name=&quot;data1&quot; value=&quot;#data1#&quot;>
<input type=&quot;hidden&quot; name=&quot;data2&quot; value=&quot;#data2#&quot;>
</form>

<form name=&quot;frmReturnToMain&quot; action=&quot;main.cfm&quot; method=&quot;POST&quot;>
<!--- use a button or link to trigger the event --->
<input type=&quot;input&quot; name=&quot;gotoproc&quot; value=&quot;Do the work&quot;
onclick=&quot;javascript:document.frmDetails.submit()&quot;>
<input type=&quot;hidden&quot; name=&quot;data1&quot; value=&quot;#data1#&quot;>
<input type=&quot;hidden&quot; name=&quot;data2&quot; value=&quot;#data2#&quot;>
<input type=&quot;hidden&quot; name=&quot;newdata&quot; value=&quot;#newdata#&quot;>
</form>


Pass a similar form back from your procedure page using
<script language=&quot;JavaScript&quot;>
document.frmReturnToMain.submit();
</script>

Hope this gives you some ideas.

D.
 
I am actually trapping the Applet's events via JavaScript. The events will fire javaScript functions that will either have to redirect to a .cfm (that fires the stored proc) or submit a form action.

My challenge is how do I do that without losing the page with applet in the client browser. I imagine I could open a new browser window and run the .cfm file and then close the window. However that looks bad, plus I have to fire the .cfm on every applet click.
 
Here's an idea -- put a 1x1-pixel <IMG> in your page somewhere. Write a .cfm page that executes the stored procedure and returns a blank .gif as the response instead of an HTML page. Then, when you trap the event with JavaScript, change the source of the image so that it has to go back to the server to request the image again. You can put in parameters if you want. Basic example:
Code:
  <img id=&quot;spyImg&quot; name=&quot;spyImg&quot; src=&quot;spy.cfm?event=pageLoad&quot; width=&quot;1&quot; height=&quot;1&quot; />

  <script type=&quot;text/javascript&quot;>
    var spyImg = document.getElementById(&quot;spyImg&quot;);
    function trapEvent(event)
    {
      spyImg.src = &quot;spy.cfm?event=&quot;+event+&quot;&rand=&quot;+Math.random();
    }
  </script>
This is just a basic example. The important thing is making sure the browser requests the image from the server every time the event fires and not from its cache -- that's why I added a random number to the request. You'll have to test to make sure that works on all your target browsers -- cache behavior is not well-documented.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top