1

Hi I have to show the auto complete data returned by jquery in ListBox. Is it Possible? If possible tell me the way please. I tried as below is not working.

Here is my jquery:

<script type="text/javascript">
      $(document).ready(function () {
          SearchText();
      });
      function SearchText() {
          $(".ss").autocomplete({
              source: function (request, response) {
                  $('.ui-autocomplete').css('list-style-type', 'none').css('text-decoration', 'none');
                  $.ajax({
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      url: "/Services/SearchService.asmx/SearchCategory",
                      data: "{'searchtxt':'" + document.getElementById('MainContent_searchtext').value + "'}",
                      dataType: "json",
                      success: function (data) {
                          response(data.d);
                          $(data.d).each(function(){
                              $('#ListBox1').append(response(data.d));
                          });
                      }
                  });
              }, minLength: 2
          });
      }
</script>

2 Answers 2

2

other code seems fine, just change your data appending method like this:

 success: function (data) {
     response(data.d);
     $(data.d).each(function(){ // if data.d returns a collection
         $('#ListBox1').append("<option value='"+data.d+"'>data.d</option>");
     });
 }
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

success: function (data) {
    response(data.d);
    $(data.d).each(function(){
       $('#ListBox1').append($("<option />").val(data.d).text(data.d));
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.