0

I have a Node Js server that sends a list of laws to the client side throught a variable . How can I filter the variable in the client side (according to a search of the client in an input box)?

Thanks in advance

1 Answers1

0

If you have json file you can use JSON.parse() and then filter array!

When receiving data from a web server, the data is always a string.

Parse the data with JSON.parse(), and the data becomes a JavaScript object.

If you use XMLHttpRequest:

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    var myObj = JSON.parse(this.responseText);
    document.getElementById("demo").innerHTML = myObj.name;
  }
};
xmlhttp.open("GET", "json_demo.txt", true);
xmlhttp.send();

You send a request to server and receive a string response. You should covert string(Json) to array. this.response is your json that server send to client!