cannot able to pass data from express to ejs? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Which MySQL data type to use for storing boolean valuesShould I use the datetime or timestamp data type in MySQL?Reference - What does this error mean in PHP?pass object to javascript in ExpressJSHow to pass data from client to server in express framework with jquery ajax and node js?How would I use the return data from a controller as EJS data?Getting error “TypeError: Cannot read property 'Name' of undefined” while form submitting in node.jsHow to convert to string from object req data in express node.jsError in express and ejs, for displaying data on screen from database

Why are vacuum tubes still used in amateur radios?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

How were pictures turned from film to a big picture in a picture frame before digital scanning?

How does light 'choose' between wave and particle behaviour?

What does this say in Elvish?

Are sorcerers unable to use the Careful Spell metamagic option on themselves?

How often does castling occur in grandmaster games?

What are the discoveries that have been possible with the rejection of positivism?

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

A term for a woman complaining about things/begging in a cute/childish way

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

How does Belgium enforce obligatory attendance in elections?

Is there public access to the Meteor Crater in Arizona?

What does 丫 mean? 丫是什么意思?

What initially awakened the Balrog?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Is there any word for a place full of confusion?

Can the Flaming Sphere spell be rammed into multiple Tiny creatures that are in the same 5-foot square?

How to save space when writing equations with cases?

Misunderstanding of Sylow theory

Why are my pictures showing a dark band on one edge?

Is multiple magic items in one inherently imbalanced?

One-one communication

What's the point of the test set?



cannot able to pass data from express to ejs?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Which MySQL data type to use for storing boolean valuesShould I use the datetime or timestamp data type in MySQL?Reference - What does this error mean in PHP?pass object to javascript in ExpressJSHow to pass data from client to server in express framework with jquery ajax and node js?How would I use the return data from a controller as EJS data?Getting error “TypeError: Cannot read property 'Name' of undefined” while form submitting in node.jsHow to convert to string from object req data in express node.jsError in express and ejs, for displaying data on screen from database



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















i tried to pass a data from js file(sample.js) to ejs using res.send("filename.ejs",data) by converting a object into JSON where JSON data is displaying on console, but while trying to pass it showing an error




TypeError: Cannot create property '_locals' on string




can some one help with this and tell me how to call them in ejs file










share|improve this question



















  • 2





    Please consider making an edit to clarify your question. In the meantime, if you need to send the contents of a file from your node/express server to ejs in your browser, try res.sendFile(). expressjs.com/en/4x/api.html#res.sendFile

    – O. Jones
    Mar 8 at 11:47











  • As O. Jones said, we really need a lot more information. Can you attach your code and describe the output you expect from the client in detail?

    – Elliot Blackburn
    Mar 8 at 13:18

















0















i tried to pass a data from js file(sample.js) to ejs using res.send("filename.ejs",data) by converting a object into JSON where JSON data is displaying on console, but while trying to pass it showing an error




TypeError: Cannot create property '_locals' on string




can some one help with this and tell me how to call them in ejs file










share|improve this question



















  • 2





    Please consider making an edit to clarify your question. In the meantime, if you need to send the contents of a file from your node/express server to ejs in your browser, try res.sendFile(). expressjs.com/en/4x/api.html#res.sendFile

    – O. Jones
    Mar 8 at 11:47











  • As O. Jones said, we really need a lot more information. Can you attach your code and describe the output you expect from the client in detail?

    – Elliot Blackburn
    Mar 8 at 13:18













0












0








0








i tried to pass a data from js file(sample.js) to ejs using res.send("filename.ejs",data) by converting a object into JSON where JSON data is displaying on console, but while trying to pass it showing an error




TypeError: Cannot create property '_locals' on string




can some one help with this and tell me how to call them in ejs file










share|improve this question
















i tried to pass a data from js file(sample.js) to ejs using res.send("filename.ejs",data) by converting a object into JSON where JSON data is displaying on console, but while trying to pass it showing an error




TypeError: Cannot create property '_locals' on string




can some one help with this and tell me how to call them in ejs file







mysql express ejs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 15:05









kalehmann

2,7781124




2,7781124










asked Mar 8 at 11:40









shivashiva

11




11







  • 2





    Please consider making an edit to clarify your question. In the meantime, if you need to send the contents of a file from your node/express server to ejs in your browser, try res.sendFile(). expressjs.com/en/4x/api.html#res.sendFile

    – O. Jones
    Mar 8 at 11:47











  • As O. Jones said, we really need a lot more information. Can you attach your code and describe the output you expect from the client in detail?

    – Elliot Blackburn
    Mar 8 at 13:18












  • 2





    Please consider making an edit to clarify your question. In the meantime, if you need to send the contents of a file from your node/express server to ejs in your browser, try res.sendFile(). expressjs.com/en/4x/api.html#res.sendFile

    – O. Jones
    Mar 8 at 11:47











  • As O. Jones said, we really need a lot more information. Can you attach your code and describe the output you expect from the client in detail?

    – Elliot Blackburn
    Mar 8 at 13:18







2




2





Please consider making an edit to clarify your question. In the meantime, if you need to send the contents of a file from your node/express server to ejs in your browser, try res.sendFile(). expressjs.com/en/4x/api.html#res.sendFile

– O. Jones
Mar 8 at 11:47





Please consider making an edit to clarify your question. In the meantime, if you need to send the contents of a file from your node/express server to ejs in your browser, try res.sendFile(). expressjs.com/en/4x/api.html#res.sendFile

– O. Jones
Mar 8 at 11:47













As O. Jones said, we really need a lot more information. Can you attach your code and describe the output you expect from the client in detail?

– Elliot Blackburn
Mar 8 at 13:18





As O. Jones said, we really need a lot more information. Can you attach your code and describe the output you expect from the client in detail?

– Elliot Blackburn
Mar 8 at 13:18












3 Answers
3






active

oldest

votes


















0














res.send() is used for send data there is no need to point ejs file



res.send takes array as parameter (res.send([body])) and you can get it in ejs like data



for example



NODEJS
res.send(message: 'hello')



filename.ejs



<div> message </div> or <%= JSON.stringify(message) %>


also as Express 5x does not support res.send() method you can use



res.status(200).send(message: 'hello)


(you did not admit you express version)






share|improve this answer






























    0














    Note that you should not use the .ejs extension in res.render, despite other answers to your question suggesting that you do so.

    When you call res.render('myView'), ejs looks for a template called myView.ejs in a folder called views (which is set as the default folder to use by ejs)



    for example:



    res.render('myView.ejs',
    data:data,
    foo:'foo'
    );


    ejs will look for a view called myView.ejs.ejs (or it might just fail alltogether).



    To access the data on your template, you would do the following:



    app.js:



    app.get('/somePathHere', function(req, res) 
    res.render('myView',
    data:data,
    foo:'foo'
    );
    );


    myView.ejs:



    <% data.forEach(function(item) %>
    //do something

    <% ); %>

    <%= foo %>


    Note that when accessing a variable, you use the <%= varNameHere %>, and when writing any type of function, you would omit the =.






    share|improve this answer
































      0














      You're sending data to your view so update your code with this and try



       res.render("filename",
      data:"hello"
      );


      Or you can pass whole data



       res.render("filename",data:data);


      And in your ejs file access it like this



       <div> <%= data %> <div>





      share|improve this answer




















      • 1





        You can't use .ejs in the filename when using res.render('filename')...

        – Caleb Goodman
        Mar 8 at 21:50











      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062513%2fcannot-able-to-pass-data-from-express-to-ejs%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      res.send() is used for send data there is no need to point ejs file



      res.send takes array as parameter (res.send([body])) and you can get it in ejs like data



      for example



      NODEJS
      res.send(message: 'hello')



      filename.ejs



      <div> message </div> or <%= JSON.stringify(message) %>


      also as Express 5x does not support res.send() method you can use



      res.status(200).send(message: 'hello)


      (you did not admit you express version)






      share|improve this answer



























        0














        res.send() is used for send data there is no need to point ejs file



        res.send takes array as parameter (res.send([body])) and you can get it in ejs like data



        for example



        NODEJS
        res.send(message: 'hello')



        filename.ejs



        <div> message </div> or <%= JSON.stringify(message) %>


        also as Express 5x does not support res.send() method you can use



        res.status(200).send(message: 'hello)


        (you did not admit you express version)






        share|improve this answer

























          0












          0








          0







          res.send() is used for send data there is no need to point ejs file



          res.send takes array as parameter (res.send([body])) and you can get it in ejs like data



          for example



          NODEJS
          res.send(message: 'hello')



          filename.ejs



          <div> message </div> or <%= JSON.stringify(message) %>


          also as Express 5x does not support res.send() method you can use



          res.status(200).send(message: 'hello)


          (you did not admit you express version)






          share|improve this answer













          res.send() is used for send data there is no need to point ejs file



          res.send takes array as parameter (res.send([body])) and you can get it in ejs like data



          for example



          NODEJS
          res.send(message: 'hello')



          filename.ejs



          <div> message </div> or <%= JSON.stringify(message) %>


          also as Express 5x does not support res.send() method you can use



          res.status(200).send(message: 'hello)


          (you did not admit you express version)







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 15:31









          iliailia

          11113




          11113























              0














              Note that you should not use the .ejs extension in res.render, despite other answers to your question suggesting that you do so.

              When you call res.render('myView'), ejs looks for a template called myView.ejs in a folder called views (which is set as the default folder to use by ejs)



              for example:



              res.render('myView.ejs',
              data:data,
              foo:'foo'
              );


              ejs will look for a view called myView.ejs.ejs (or it might just fail alltogether).



              To access the data on your template, you would do the following:



              app.js:



              app.get('/somePathHere', function(req, res) 
              res.render('myView',
              data:data,
              foo:'foo'
              );
              );


              myView.ejs:



              <% data.forEach(function(item) %>
              //do something

              <% ); %>

              <%= foo %>


              Note that when accessing a variable, you use the <%= varNameHere %>, and when writing any type of function, you would omit the =.






              share|improve this answer





























                0














                Note that you should not use the .ejs extension in res.render, despite other answers to your question suggesting that you do so.

                When you call res.render('myView'), ejs looks for a template called myView.ejs in a folder called views (which is set as the default folder to use by ejs)



                for example:



                res.render('myView.ejs',
                data:data,
                foo:'foo'
                );


                ejs will look for a view called myView.ejs.ejs (or it might just fail alltogether).



                To access the data on your template, you would do the following:



                app.js:



                app.get('/somePathHere', function(req, res) 
                res.render('myView',
                data:data,
                foo:'foo'
                );
                );


                myView.ejs:



                <% data.forEach(function(item) %>
                //do something

                <% ); %>

                <%= foo %>


                Note that when accessing a variable, you use the <%= varNameHere %>, and when writing any type of function, you would omit the =.






                share|improve this answer



























                  0












                  0








                  0







                  Note that you should not use the .ejs extension in res.render, despite other answers to your question suggesting that you do so.

                  When you call res.render('myView'), ejs looks for a template called myView.ejs in a folder called views (which is set as the default folder to use by ejs)



                  for example:



                  res.render('myView.ejs',
                  data:data,
                  foo:'foo'
                  );


                  ejs will look for a view called myView.ejs.ejs (or it might just fail alltogether).



                  To access the data on your template, you would do the following:



                  app.js:



                  app.get('/somePathHere', function(req, res) 
                  res.render('myView',
                  data:data,
                  foo:'foo'
                  );
                  );


                  myView.ejs:



                  <% data.forEach(function(item) %>
                  //do something

                  <% ); %>

                  <%= foo %>


                  Note that when accessing a variable, you use the <%= varNameHere %>, and when writing any type of function, you would omit the =.






                  share|improve this answer















                  Note that you should not use the .ejs extension in res.render, despite other answers to your question suggesting that you do so.

                  When you call res.render('myView'), ejs looks for a template called myView.ejs in a folder called views (which is set as the default folder to use by ejs)



                  for example:



                  res.render('myView.ejs',
                  data:data,
                  foo:'foo'
                  );


                  ejs will look for a view called myView.ejs.ejs (or it might just fail alltogether).



                  To access the data on your template, you would do the following:



                  app.js:



                  app.get('/somePathHere', function(req, res) 
                  res.render('myView',
                  data:data,
                  foo:'foo'
                  );
                  );


                  myView.ejs:



                  <% data.forEach(function(item) %>
                  //do something

                  <% ); %>

                  <%= foo %>


                  Note that when accessing a variable, you use the <%= varNameHere %>, and when writing any type of function, you would omit the =.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 8 at 21:52

























                  answered Mar 8 at 21:47









                  Caleb GoodmanCaleb Goodman

                  1,2161518




                  1,2161518





















                      0














                      You're sending data to your view so update your code with this and try



                       res.render("filename",
                      data:"hello"
                      );


                      Or you can pass whole data



                       res.render("filename",data:data);


                      And in your ejs file access it like this



                       <div> <%= data %> <div>





                      share|improve this answer




















                      • 1





                        You can't use .ejs in the filename when using res.render('filename')...

                        – Caleb Goodman
                        Mar 8 at 21:50















                      0














                      You're sending data to your view so update your code with this and try



                       res.render("filename",
                      data:"hello"
                      );


                      Or you can pass whole data



                       res.render("filename",data:data);


                      And in your ejs file access it like this



                       <div> <%= data %> <div>





                      share|improve this answer




















                      • 1





                        You can't use .ejs in the filename when using res.render('filename')...

                        – Caleb Goodman
                        Mar 8 at 21:50













                      0












                      0








                      0







                      You're sending data to your view so update your code with this and try



                       res.render("filename",
                      data:"hello"
                      );


                      Or you can pass whole data



                       res.render("filename",data:data);


                      And in your ejs file access it like this



                       <div> <%= data %> <div>





                      share|improve this answer















                      You're sending data to your view so update your code with this and try



                       res.render("filename",
                      data:"hello"
                      );


                      Or you can pass whole data



                       res.render("filename",data:data);


                      And in your ejs file access it like this



                       <div> <%= data %> <div>






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 8 at 22:16

























                      answered Mar 8 at 16:29









                      Muhammad ShareyarMuhammad Shareyar

                      17010




                      17010







                      • 1





                        You can't use .ejs in the filename when using res.render('filename')...

                        – Caleb Goodman
                        Mar 8 at 21:50












                      • 1





                        You can't use .ejs in the filename when using res.render('filename')...

                        – Caleb Goodman
                        Mar 8 at 21:50







                      1




                      1





                      You can't use .ejs in the filename when using res.render('filename')...

                      – Caleb Goodman
                      Mar 8 at 21:50





                      You can't use .ejs in the filename when using res.render('filename')...

                      – Caleb Goodman
                      Mar 8 at 21:50

















                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55062513%2fcannot-able-to-pass-data-from-express-to-ejs%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                      Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                      Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved