0

I have a JavaScript file which uses an Ajax call to another JavaScript file (which runs server commands and produces a JSON result string).

 $.getJSON("fileWithServerData.js", function (data) {

    //use data here
});

No PhP here!

How can I then return my JSON string to the Ajax call?

var socket;

socket = io.connect('http://localhost:5000');

socket.on('Id', AFunction);


function AFunction(data) {

   //send data back to the calling JavaScript file
   //???
   //???
   console.log(data) // does NOT work
   //???

}
  • 2
    Your question is unclear. Your tags suggest that you have some server side code written using Node.js which outputs JSON. If it isn't working, then you'll have to show us *that* code. – Quentin Apr 05 '18 at 15:49
  • The JSON string should be in the response body. – 4castle Apr 05 '18 at 15:49
  • simply `console.log(data)` , assuming that your API endpoint work – Abslen Char Apr 05 '18 at 15:50
  • I'm guessing you want to get the output from whatever code runs in `fileWithServerData.js`? `eval` would be your only option here. How you'd direct the "output" to a variable is strictly depended on the code in `fileWithServerData.js`. – Sergiu Paraschiv Apr 05 '18 at 15:57
  • I have just posted the fileWithServerData.js - which has data that I am trying to return to the calling AJAX code/file. – noviceCoder Apr 05 '18 at 20:23

0 Answers0