Monday, January 19, 2015

Sample Ajax call using Jquery


function getNewAccountsHtml() {
 $.ajax({
     type: 'GET',
     cache: false,
     async: false,
     url: 'getXXX?hours=' + <%= Integer.parseInt(Properties.Hours())%>,
     data: $("#id").serialize(),
     success: function(data) {
      $("#newAccountsHtml").html(data.xyz); //the java method sets html.put("xyz", "value") and struts.xml has the action configured
      $("#newAccountsHtml").css("display", "block");
      $("#newAccountsUpdateTime").html(getCurrentTimestamp());
     },
     error: function(XMLHttpRequest, textStatus, errorThrown) {
         alert("Server Unavailable");
     },
     dataType: "json"
 });
}

No comments:

Post a Comment