0

js and javascript... i getting problem in how send array value from client side .js file to server side app.js into post request.

var = testParamterName=[],testParameterValue=[];

    $("#Table1 tbody tr").each(function(rowinex){
    // this basically gets the 2 column values that i require
          var i=0;

          $.each(this.cells,function(callIndex,cell){
            if(i==2) //parameter value
            {
              testParamterName.push(cell.textContent);
            } else if(i==3)
            {
            testParameterValue.push(cell.textContent);

            }
         i++;
       });
        i=0;
     });

i am getting values from a table using jQuery in a file called test.js after saving the table values into two array namely 'testParameterValue' and 'testParamterName'

now i want to send these 2 array values to my server side .js file app.js

i used the module.exports = {testParameterValue , testParametername}; but this gives an error saying module not defined..

i have tried searching the web couldn't find the solution to my problem ... the closest solution i found was that .... cannot run module.exports into files that run in the browser.

i have skipped the code where i handled a click event for submit

please help me ...Thanks in advance :)

1 Answers1

0

First of all you need to setup your server-side application with e.g. NodeJS and express. Your basic app will listen on the specific port, like localhost:3000. Then you need to request this URL with your client-side JavaScript code. This issue is very well explained over here: How to process POST data in Node.js?

  • I have done all that and I know how that works... I simply want to send some custom data outside of body of form that's accessed in post server side... I've setup everything necessary... Just cant export data from js file that's linked with the webpage – Mohammad Awais Apr 01 '20 at 10:17
  • You can't use `require` client-side, it is node.js built-in. Also if you want to send POST request your data should be in stringified JSON form(not array), and `body-parser` should parse it into JSON on server-side. – Adrian Solarczyk Apr 01 '20 at 12:02
  • .... I want to send array data from client side js file to server side post request.... For that I have To convert the array Into json file and then send it to the server side... – Mohammad Awais Apr 01 '20 at 20:36
  • Well, it is possible you let external service to do server-side stuff. For examlple https://formspree.io but i recommend you studying express example in node environment. – Adrian Solarczyk Apr 01 '20 at 23:12