Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
jQuery : post/get using data() as param object
  1. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <title>Recursive call when post request</title>
  7. <script type="text/javascript" src="jquery-1.5.1.js"></script>
  8. <script type="text/javascript">
  9.     $(function() {
  10.         var count = 0;
  11.         $('input:button').click(function() {
  12.             // identity
  13.             count++;
  14.             var tick = count;
  15.             // post url
  16.             var url = '${contextPath}/';
  17.             // post param
  18.             var param = $(this).data();
  19.             console.log(param);
  20.             $('<div>(' + tick + ') Post to : ' + url + '</div>').appendTo(document.body);
  21.             $.post(url, param, function(data) {
  22.                 $('<div style="color:blue;">(' + tick + ') Ajax works successfully.</div>').appendTo(document.body);
  23.             });
  24.         });
  25.     });
  26. </script>
  27. </head>
  28. <body>
  29. <input type="button" value="click to post" data-action="test" data-name="bruce" data-age="31" />
  30. </body>
  31. </html>
ボタンをクリックすると、data()のオブジェクトがハンドルを値を持っているため、postするときにハンドルは再び執行することになる。つまり、クリック事件は繰り返しする。この現象を避けるには、ハンドル/イベントを削除しなければならない。