thymeleaf のタグをAjaxで更新かけた後のJQueryの動作
判りにくくてすみません。
index.htmlには、「 hello 」と 「 AJAX 」と言うボタンがありますが、
「 hello 」は、th:substituteby で読み込みをかけたtestBtn.html にあります。
その状態で、「 hello 」ボタン押下で、「 hello 」とアラートします。
次に、「 AJAX 」ボタン押下で、 testBtn.html を更新かけます。
WEB上では、全く見た目も変わらず、ソースも変わりませんが、
次に、「 hello 」を押下しても、「 hello 」とアラートしません。
そういうものなのか、なにか足りないのでしょうか?
どうぞよろしくお願いいたします。
該当のソースコード
html
1 2<div id="testInc"> 3 4 <div th:substituteby="common/testBtn :: test_btn"></div> 5 6</div> 7 8<button type=button class= "AjaxhelloClick">Ajax</button> 9 10
html
1<!DOCTYPE html> 2<html> 3<head> 4<meta charset="UTF-8"> 5<title>Insert title here</title> 6</head> 7<body> 8 9 <div th:fragment="test_btn"> 10 11 <button type=button class= "helloClick">hello</button> 12 13 14</div> 15 16 17</body> 18</html> 19
JQuery
1 2 $('.helloClick').click(function() { 3 4 alert("hello !!"); 5 6 }); 7 8 $('.AjaxhelloClick').click(function() { 9 10 11 $.ajax({ 12 url: "/testAjax", 13 type: "POST", 14 dataType: "html" 15 }).done(function(data) { 16 17 //alert("ok"); 18 $('#testInc').html(data); 19 20 }).fail(function(XMLHttpRequest, textStatus, errorThrown) { 21 22 alert("error"); 23 24 }); 25 26 }); 27
java
1 2@RequestMapping(value="/testAjax", method=RequestMethod.POST, produces="text/plain;charset=UTF-8") 3 public String testAjax() { 4 5 return "common/testBtn :: test_btn"; 6 7 } 8 9}
補足情報(FW/ツールのバージョンなど)
STS4
JDK11
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。