2016-06-22 15 views
0

我想使用angular js, html, javascript創建dynamic query(Select * from <table name> where ..)。下拉應該爲條件('and' , 'or', etc)e.g. -> select <dropdown> from <dropdown> where <dropdown>。 我是新手。所以請以適當的例子來解釋。如何使用AJAX創建動態查詢

+2

請分享迄今爲止您嘗試的內容。 –

+0

一個簡單的例子就是對你的控制器進行ajax調用,從數據庫獲取數據,然後將數據綁定到你的下拉菜單。 – SiddP

+0

你可以舉個例子嗎? – Priyanka

回答

0
$.ajax({ 
    type: 'POST', 
    url: 'DropDownController', 
    dataType: 'json', 
    success: function(result) { 
     $.each(result, function() { 
      $("#drpDown").append(
       $('<option/>', { 
        value: this, 
        html: this 
       }) 
      ); 
     }); 
    } 
}); 

在端點會發生什麼情況是有些控制器DropDownController可能是,如果你使用的是Spring MVC它會是這樣的/DropDownController在那裏你可以使用orm寫你query to call database或任何你使用和返回是jsonbinds to the dropdown with id="drpDown"