2014-03-06 184 views
0

我有以下代码。我有2个选择选项菜单。每当他们中的任何一个发生变化时,我都想向一个servlet发送一个AJAX请求。通过使用来自servlet的数据,我想把它写在我的html中。html下拉菜单动态变化

我该怎么做?

感谢

<div class="p_inforoom"> 
    <input type="hidden" th:value="${hotelDetail.deal.id}" id="dealId" /> 

    <h3>Oda Bilgileri :<b th:text="${hotelDetail.deal.room.name}"></b></h3> 
    <select name="numberOfNights" id="night" onchange="GetNights(this)"> 
     <option th:each="rooms:${roomsLeft}" th:text="${rooms}" th:value="${rooms}" id="roomLeft" > </option> 

    </select> 
    <select name="roomType" id="room" onchange="GetRooms()"> 
     <option class="1" value="1" >Tek kişilik</option> 
     <option class="2" selected="selected" value="2" >Çift kişilik</option> 
    </select> 
</div> 
+0

'th:value =“$ {hotelDetail.deal.id}”'既不是HTML也不是JavaScript,所以如果这是类似于asp或其他东西,请包含这些标签。 – Joeytje50

+0

İT的thymeleaf从servlet接受对象并将其写入html中。 Thymeleaf的主要目标是提供创建模板的优雅和格式良好的方式。其标准和SpringStandard方言允许您创建强大的自然模板,可以通过浏览器正确显示,因此也可以用作静态原型。您还可以通过开发自己的方言来扩展Thymeleaf。 – serkan

+2

好的,销售情况良好,但我所说的只是将标签添加到您的问题中,以便人们在点击问题之前知道此问题的用途。我现在已经为你添加了它。 – Joeytje50

回答

0

你会得到从“成功”了ajax的响应,你可以阅读dataand其分配到任何HTML元素要与它分配

$.ajax({ 
    type: 'POST', 
    url: requestUrl, 
    data: postData, // if any 
    contentType: "application/json; charset=utf-8", 
    dataType: 'json', 
    success: function (data) { 
     //data has the response from the url 
    } 
    }}); 
0

在jquery中,您可以通过这样做

$('#room').on('change',function(){ 
     $.ajax({ 
      url:"", 
      dataType : "",//json text 
      type : "",//get or post 
      data:"", 
      success:function(data){ 
     alert(data.output); 
}); 
}); 
0

您可以使用以下选择更改:

$("#room").change(function() { 
alert("Handler for .change() called."); 
}); 

Source for .change

对于Ajax查询,你可以在看信息:Ajax。您可以在下面找到该页面的一个示例。

$.ajax({ 
    type: "POST", 
    url: "some.php", 
    data: { name: "John", location: "Boston" } 
}).done(function(msg) { 
    alert("Data Saved: " + msg); 
})