Home javascript Data exchange between JavaScript and PostgreSQL (without node.js)

Data exchange between JavaScript and PostgreSQL (without node.js)

Author

Date

Category

Tell me, please, how can I “make friends” js and pg?

As far as I understand it directly from the browser without applying Nodejs, this does not turn this?! But …

What we have:

  1. site with forms from which the data should fall into PG.

everything is written on JS and the logic of processing and working with data in forms too on it.

  1. Turn this operation with the use of NodeJS is no possibility due to the closedness of the system !!!

  2. To implement the Wishlist, a bunch of PHP and JS is seen, but the question arises, is it possible to process the data, and then call the PHP script for transmitting generated data.

and without taking into account intermediate storage links of this data, i.e. Without using JSON.

For example, JS’s work results are placed in the PHP script, which sends data in the database. Here you can use interpolation.

But how to deal with the data request from the database that PHP receives and gently transmits them to JS for the corresponding output on the front ?!

I will be happy to answer and light thoughts)))


Answer 1

I will tell you about another way. Not standard. You need to embed a Hasura Engine that uses Graphql and link it to your postgresql database. It will be your replacement Nodju, that is, you don’t need to give anything, you just need to configure Hasura Engine.
Next, requests will occur from the front immediately to the paku, without the introduction of Nodja.
Guides make it a lot.
An example of a request from the front will look something like this

var data = json.stringify ({
  Query: `{
   \ N Posts {
   \ ND.
   \ N info
   \ n}
   \ N} `,
   variables: {}
 });
   var config = {
   Method: 'POST',
   URL: 'URL',
   Headers: {
     'Hasura-Admin-Secret': 'PASS',
     'Content-Type': 'Application / Json'
   },
   Data: Data.
   };
   AXIOS (Config)
   .Then (Function (Response) {
   Console.log (json.stringify (response.data));
   })
   .catch (FUNCTION (Error) {
   Console.log (Error);
   });

Answer 2

You can send Ajax requests for PHP file and from it through a global array $ _Get or $ _Post to receive data. Next (in the PHP file), send data to the database and via ECHO to display a message that the data has been successfully sent. In JS When the Ajax request is sent, you can get an answer from the same PHP file without rebooting the page. I advise you to read about AJAX + PHP.


Answer 3

Thoughts are as follows. What can JS make a substantially cross-protema and cross-platform safely from the browser? Send data (Socket, XmlHttpRequest). So it will need to be processed. An option that you want it to be postgres itself, but there is no such box. It remains to write a Web server and not at all necessary on node.js the benefit of them is not enough. It remains to determine what you are preferable to write and the presence of the necessary libraries.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions