vendredi 10 juin 2016

dynamically append options to a select tag


So I have basically saw every post related to my little issue here but unfortunately none of them has worked for me.

I am receiving this list that contains some strings from an ASP.net controller which is working flawlesly. Also when I console.log() it works fine, it also workes when I alert it. But when I try to append the result it doesn't work.

My jQuery code:

$.ajax({
url: '/Concurrent/GetList',
type: 'POST',
dataType: 'json',
data: {
    RefAO: $("#txt_search").val()
},
success: function(list) {
    if (list == "fail") {
        alert("erreur");
    }
    else {
        $.each(list, function(index, item) {
           //alert("Ref : " + item);
           $("#Combo").append("<option>" + item + "</option>");
        });
    }
}
});

And here is my HTML code:

@{
ViewBag.Title = "Créer Concurrent";
ViewBag.Page = "Création d'un Nouveau Concurrent";
Layout = "~/Views/Shared/_Layout.cshtml";
 }
<head>
  <link href="~/Content/StyleConcurrent.css" rel="stylesheet" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <link href="~/Content/bootstrap-select.css" rel="stylesheet" />
  <script src="~/Scripts/bootstrap-select.js"></script>
  <script src="~/Scripts/ConcurrentScript.js"></script>
</head>
<form id="search-form" class="form-inline" role="form" method="post">
  <!--Block Recherche-->
    <div class="input-group">
    <input id="txt_search" type="text" class="form-control search-form" placeholder="Réference Appel d'Offre" required>
    <span class="input-group-btn">
        <button id="btRech" class="btn btn-primary search-btn" data-target="#search-form" >
            <i class="fa fa-play"></i>
        </button>
    </span>
</div>
<!--Block DropDownList-->
<div id="DropDown">
    <select id="Combo" class="selectpicker">

    </select>
</div>


Aucun commentaire:

Enregistrer un commentaire