Web Connection
Is it possible to call a VFP function without submitting or leaving the current web page
Gravatar is a globally recognized avatar based on your email address. Is it possible to call a VFP function without submitting or leaving the current web page
  Chris Jewell
  All
  Jan 10, 2020 @ 02:49am

Hi Rick,

Hopefully, this is a quick question.

Is it possible to call a VFP function without submitting or leaving the current web page?

What I'm trying to achieve is this, on a web page the user is going to click a timer when they start an action and this DateTime needs to be recorded onto a .dbf without leaving the form.

Any ideas appreciated? Thanks, Chris

Gravatar is a globally recognized avatar based on your email address. re: Is it possible to call a VFP function without submitting or leaving the current web page
  Rick Strahl
  Chris Jewell
  Jan 10, 2020 @ 04:14am

Yes you need to make an asynchronous 'AJAX' call.

There are a number of ways to do this but the simplest is to use ww.jquery.js and the ajaxJson() method that lets you make a call to the server and return a result via JSON.

There aren't any real simple examples, but there's a walk through for creating JSON REST Web Services that demonstrates how to create a service you can call from the browser.

The last topic in that walkthrough talks about how to call the server.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Is it possible to call a VFP function without submitting or leaving the current web page
  Chris Jewell
  Rick Strahl
  Jan 13, 2020 @ 08:10am

Thanks Rick, I'll give it a go 😃

Gravatar is a globally recognized avatar based on your email address. re: Is it possible to call a VFP function without submitting or leaving the current web page
  Rick Strahl
  Chris Jewell
  Jan 13, 2020 @ 12:29pm

I probably made that sound a lot more scary than it is...

Another option is to just use jQuery.ajax() or jQuery.get() to call a separate URL and retrieve some data.

Just wrote up a topic that demonstrates this here:

Using jQuery.get() for Simple Ajax Callbacks

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Is it possible to call a VFP function without submitting or leaving the current web page
  Chris Jewell
  Rick Strahl
  Jan 15, 2020 @ 03:33am

Thank you so much Rick this is really helpful 😃

Gravatar is a globally recognized avatar based on your email address. re: Is it possible to call a VFP function without submitting or leaving the current web page
  Marty
  Chris Jewell
  Jan 29, 2020 @ 01:09pm

Is there a modern way of storing the hashtag when the page changes? It would seem there should be a way of using the ES6 "fetch()" function to store the hashtag array? I'm using a routine from the book "Single Page Application" from 2014 - which Works but there must be something better.

Gravatar is a globally recognized avatar based on your email address. re: Is it possible to call a VFP function without submitting or leaving the current web page
  Rick Strahl
  Marty
  Jan 29, 2020 @ 01:53pm

Not sure what you're asking or saying in relation to Chris' question here...

fetch() is fine as long as you're dealing with new browsers. Older devices and anything IE won't work with the fetch() API so using it is still a bit iffy (although getting a lot less so).

I'm not sure what you mean by 'storing a hashtag'. You mean adding it to the history? There's the pushState API that can be used to push URLs onto the history stack.

+++ Rick ---

© 1996-2020