R
R
redesupar2019-06-17 06:06:32
JavaScript
redesupar, 2019-06-17 06:06:32

How to display certain data from json based on url parameters?

I access two files via json (1.php is the id and names of branches. 2.php is the id and data of branches)
I display the first file as a menu with links, where id, sid, period, etc. when clicked, the data from the second file is also updated. How can I display the name of the selected branch?

jQuery(function () {
        $.ajax({
            url: 'dept3.php'
            , type: 'GET'
            , data: {Sid: $("#Sid").val()}
            , success: function (data) {
                console.log('dept3.php 163');
                	// console.log(data);
                var result = JSON.parse(data);
                console.log(result);

                if (result.hasOwnProperty("error")) {
                    alert(result.error);
                } else {
          
                    var $m = $("#menu");
                    $.each(result.data, function(index, value){
                        if (value.parentIsn == -1) {
                            $m.append("<li class='isn-"+ value.isn +"' data-isn='" + value.isn + "'><a href='javascript:void(0)'><span>" + value.name + "</span></a><ul></ul></li>");
                        } else {
                            $('.isn-' + value.parentIsn).children('ul').append("<li class='isn-"+ value.isn +"' data-isn='" + value.isn + "' data-deptisn='" + value.isn + "'><a href='javascript:void(0)'><span>" + value.name + "</span></a><ul></ul></li>");
                        }
                    });
                    $('#menu li li').each(function() {
                        if ($(this).children('ul').children().length) {
                            var isn = $(this).data('isn');
                            var deptisn = $(this).data('deptisn');
                            $(this).children('ul').children().first()
                                .prepend("<li class='first' data-isn='" + isn + "' data-deptisn='" + deptisn + "'><a href='javascript:void(0)'><span>Все " + $(this).children('a').text() + "</span></a><ul></ul></li>");
                        }
                    });
                    initMenu();

                }
            }
        });

    });


The point is to take isn= from url and output its value.name to div id="name" . But when outputting, it displays all the names

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question