Ajax повторяющаяся проблема - PullRequest
0 голосов
/ 06 августа 2020

Добрый день!

У меня проблема с отображением дубликатов в таблице медицинских рецептов, и я считаю, что это результат сравнения Ajax GET и POST, но я недостаточно знаю о javascript или ajax, чтобы исключить любой из них. Будем очень благодарны любой помощи! Спасибо!

$. ajax ({url: url, data: {}, type: 'GET', success: function (medicationReceived) {if (medicationReceived) {console.log ("Printing medicationReceived) "); console.log (medicationReceived); localStorage.setItem (" MedicationList ", JSON .stringify (medicationReceived));

                    var output = [];

                    //call the current schedule
                    //var currentSchedule = localStorage["selectedSchedule"];

                    //if(purpose == ""){

                    //DO: 2019-08-28 Get all medication that's not bubble pack
                    output = filteredData(medicationReceived);
                    console.log("printing output");
                    console.log(output);
                    //DO: 2019-08-28 Get all medication that's bubble pack
                    output2 = filteredDataWithPack(medicationReceived);
                    //DO: 2019-09-04 if bubble pack medication is empty then the Distributed checkbox is hidden
                    if (output2 == "") {
                        $('.bubblePackDistributedLabel').css('display', 'none');
                    }
                    console.log("printing output2");
                    console.log(output2);

                    //passed it to another function that will
                    //display the data into the table
                    displayMedicationReceivedToTable(output);
                    displayMedicationReceivedRefusedToTable(output2);
                }
            }
        });
    }

////////// Функции

    function filteredData(list, sched) {

        //create a blank object variable
        var filteredData = [];

        //then display all the data which AM_flag is equal to true and BUBBLEPACK_flag is equal to false
        //DO: 2019-09-16 added ("PRN_flag": "False") in below line to remove PRN medications in the list
        filteredData = _.where(list, { "BUBBLEPACK_flag": "False", "PRN_flag": "False" });

        //console.log("outputIndividualMedication");
        //console.log(filteredData);

        localStorage.setItem("IndividualMedication", JSON.stringify(filteredData));
        //then return the filtered data
        return filteredData;

    }

    //DT 2019-07-15 let us create a function that will filter the data with bubble pack
    function filteredDataWithPack(list, sched) {

        var filteredData = [];

        //store the filtered data where BUBBLEPACK_flag is equal to true

        //then display all the data which BUBBLEPACK_flag is equal to false
        filteredData = _.where(list, { "BUBBLEPACK_flag": "True" });

        localStorage.setItem("BubblePackMedication", JSON.stringify(filteredData));


        //then return the filtered data
        return filteredData;

    }

$.ajax({
                url: url,
                data: {},
                type: 'GET',
                success: function (medicationReceived) {
                    if (medicationReceived) {
                        console.log("printing medicationReceived");
                        console.log(medicationReceived);
                        localStorage.setItem("MedicationList", JSON.stringify(medicationReceived));

                        var output = [];

                        //call the current schedule
                        //var currentSchedule = localStorage["selectedSchedule"];

                        //if(purpose == ""){

                        //DO: 2019-08-28 Get all medication that's not bubble pack
                        output = filteredData(medicationReceived);
                        console.log("printing output");
                        console.log(output);
                        //DO: 2019-08-28 Get all medication that's bubble pack
                        output2 = filteredDataWithPack(medicationReceived);
                        //DO: 2019-09-04 if bubble pack medication is empty then the Distributed checkbox is hidden
                        if (output2 == "") {
                            $('.bubblePackDistributedLabel').css('display', 'none');
                        }
                        console.log("printing output2");
                        console.log(output2);

                        //passed it to another function that will
                        //display the data into the table
                        displayMedicationReceivedToTable(output);
                        displayMedicationReceivedRefusedToTable(output2);
                    }
                }
            });
        }

//////////Functions

        function filteredData(list, sched) {

            //create a blank object variable
            var filteredData = [];

            //then display all the data which AM_flag is equal to true and BUBBLEPACK_flag is equal to false
            //DO: 2019-09-16 added ("PRN_flag": "False") in below line to remove PRN medications in the list
            filteredData = _.where(list, { "BUBBLEPACK_flag": "False", "PRN_flag": "False" });

            //console.log("outputIndividualMedication");
            //console.log(filteredData);

            localStorage.setItem("IndividualMedication", JSON.stringify(filteredData));
            //then return the filtered data
            return filteredData;

        }

        //DT 2019-07-15 let us create a function that will filter the data with bubble pack
        function filteredDataWithPack(list, sched) {

            var filteredData = [];

            //store the filtered data where BUBBLEPACK_flag is equal to true

            //then display all the data which BUBBLEPACK_flag is equal to false
            filteredData = _.where(list, { "BUBBLEPACK_flag": "True" });

            localStorage.setItem("BubblePackMedication", JSON.stringify(filteredData));


            //then return the filtered data
            return filteredData;

        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...