简体   繁体   中英

How can I export data from ajax function into an express js server

How can I send data from a separate js file into my server in express js?

I'm trying to parse an xml file with ajax/jquery and send the data to an express js server. The parser sits in a separate file under /public/javascripts. I get this error message: ReferenceError: module is not defined.

This is an excerpt from parseBooks.js where I make the ajax call:

module.exports= {
   parseBook: function(){
     $(function(){ 
     ....

and then in my app.js server I require the file in question:

var bookParser= var bookParser= require('./public/javascripts/parseBooks');    

Can you do a jQuery post, with your data variable containing a string representation of the xml?

$.post( "ajax/test.html", function( data ) {
  $( ".result" ).html( data );
});

For more details: https://api.jquery.com/jquery.post/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM