0

My server (node.js) maintains an array :

var list = [];

I want to use this array in some js code (client side). I would like to retrieve it thanks to ajax. What is the best practice?

$.ajax({
    url: "http://localhost:8000/updatePendingAlerts",
    timeout: 2000,
    success: function (data)  {
      console.log(data);
      //data should be an array

    },
    error: function(jqXHR, textStatus, errorThrown) {
      clearInterval(timeout);
      alert('error ' + textStatus + " " + errorThrown);
    }
  });

1 Answers1

3

Serialise it to JSON (with JSON.stringify) and output it with an application/json content-type header.

It will then be an array in data with the client side JavaScript you already have.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335