簡體   English   中英

正在從JSON消息更新下拉列表,代碼不起作用

[英]Updating drop down from json message, code not working

我的json響應是

["Day", "Week"]

和應該運行的jQuery是

 $("#id_granularity").click(function(event)
    {

            event.preventDefault();
            var $form1=$('#dashboardForm')
            var $success2 = function(data)
            {
                    $("id_granularity").empty();


                    $.each(data,function(i,value)
                    {
                            alert("hello");
                            $("id_granularity").append($('<option>').text(value).attr('value',value));
                    });
            }
            $.ajaxSetup({
                    crossDomain: false, // obviates need for sameOrigin test
                    beforeSend: function(xhr,settings) {
                            xhr.setRequestHeader('X-CSRFToken',csrftoken);
                    }
            });
                    var dposting = $.post("/grain", $form1.serialize(), $success2, "json");
            });

事件發生,但下拉列表未更新或新項目未附加到

id_granularity

$("id_granularity")所有實例更改為$("#id_granularity")然后看看情況如何

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM