Update mySQL table in JS

I have a blank app that runs js.
Instead of calling another app to post the data to my table, how would I post directly to my table while in js?

Assuming my js has something like this:

var lat=“32.78912959”;
var lng="-96.8059256";
var deviceID=“abc123”;

Now I want to update to table with the above (in sc I would use the below):

$update_table = ‘IsawDevices’;
$update_where = “deviceID = ‘$deviceID’”;
$update_fields = array(
“lat = ‘$lat’”,
“lng = ‘$lng’”,
);

$update_sql = 'UPDATE ' . $update_table
	. ' SET '   . implode(', ', $update_fields)
	. ' WHERE ' . $update_where;
sc_exec_sql($update_sql);
sc_commit_trans();

You can do it with node.js, but it’s a bad idea.

JS is easily available with a right click. It will be very easy to find your connection string and hack your SQL server

I have found my issue, but have no idea how to fix it.
In short the code I am using works, but unless I have the result page selected, although the page refreshes and the table is updated, the table does not.
I have to be on the page for the table to be posted.

I am not sure how to change this.

I am using:

var xhttp = new XMLHttpRequest();
xhttp.open(“POST”, “https://www.xxxxxx/LocationUpdate/index.php?deviceID=” + deviceID + “&lng=” + lng + “&lat=” + lat, true);
xhttp.send();

I resolved it.
I’m running from menu, so that’s ok.
Thanks for your help