return sql command javascript code example

Example 1: return string from javascript function

<script>
function showName() {
  var result;
  result = addString('Hello', ' World');
  document.write (result );
}

// in below we will check how to return string from function
function addString(fName, lName) {
  var val;
  val = fName + lName;
  return val;  // returning string from function
}
</script>
<input type = "button" onclick = "showName()" value = "Result">
  
/*
I hope it will help you.
Namaste
Stay Home Stay Safe
*/

Example 2: js read mysql database

// Use https://github.com/JackChilds/jsmysqldb

// Then once it's setup you can just do this:

// Config that will be sent to server
const config = {
  "table" : "customers",
  "limit" : "50",
  "offset" : "0"
};

// Use the _POST_REQUEST function to send data to the server and get a response
_POST_REQUEST("link-to-server/database.php", 'config=' + JSON.stringify(config), (response) => {
  // Convert the response into an array of rows:
  var data = JSON.parse(response);
  // Now do what you want with data
  // data[row index][column name]
});

Tags:

Java Example