Advertisement
Lauda

JSONMsg

Jul 3rd, 2014
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  2. <%@page pageEncoding="UTF-8" %>
  3. <script type="text/javascript">
  4. var data = null;
  5.  
  6. <c:if test="${dataC != null}">
  7.  // Note: DO NOT INCLUDE jsonMsg.jsp TWICE!!!
  8.     data =  JSON.stringify(${dataC});
  9. </c:if>
  10.  
  11. $(document).ready(function() {
  12.     if (data != null)
  13.     {
  14.         // Parsing JSON object:
  15.  
  16.         data = $.parseJSON(data);
  17.  
  18.         // In case URL is forwarded, we will do a redirect
  19.         if (data[0].url != null)
  20.             {
  21.                 setTimeout(function() {
  22.                     window.location.href = data[0].url;
  23.                 }, 5000); // is k, 5sec
  24.             }
  25.        
  26.         // msgType is used for div class (alert-success | alert-danger)
  27.         if (data[0].msgType != null)
  28.             {
  29.                 $("#jsonMsg").addClass(data[0].msgType);
  30.             }
  31.        
  32.         // Message:
  33.         if (data[0].message != null)
  34.             {
  35.                 $("#jsonMsg").append(data[0].message);
  36.             }
  37.     }
  38. });
  39. </script>
  40.  
  41. <c:if test="${dataC != null}">
  42. <div id="jsonMsg" class="alert">
  43.     <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
  44. </div>
  45. </c:if>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement