Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS How to correctly prescribe if there is a filter for the filter?

dt65231

Coder
There is a filter.
The filter filters by the "full name" field. Everything works.
Logic:
- the user enters the criteria for the filter in <input id="fio">
- criteria fall into JS
- data is received from the database
- the HTML table is stored.

How to set up a filter for conditions:
- there is no data in the database according to criteria. Result: we get a message on the page - "No results";
- The user has cleared <input id="fio">. Result: The entire table is displayed.

I try to do it, but nothing happens.

JavaScript:
// Filter --- --- --- --- --- --- --- --- --- ---
$('# fio').on('input', function () {
var criteria = fio.value;
                    // event.preventDefault();

                    $.ajax({
                        url: "http://localhost:2000/players/getByFio ",
method: "POST",
data: { criteria: criteria },
data type: "JSON",
success: function (data) {
var html = ";                           
                            var dataState = data.length;
if (data.length > 0) {
                                Assembly records(data);
                            } // if (data length > 0) {
                            otherwise, if (data.length = 0) {
var html = ";
} // if (data.length = 0) {
                            otherwise, if (criterion.length = 0) {
                                loadAllData();
                            } // if (data.length = 1) {
                            
                        } // success: function (data) {
});
                });

20.08.2022_19-54-32.png
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom