티스토리 뷰

개발/Web

Jquery AJAX 속성 async 예제

개발자와코더사이가 PM일까? 2013. 1. 18. 00:00
반응형

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>필터</title>
<script type="text/javascript"  src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
 $("#btn").click(function(){
  $.ajax({
   url:"http://localhost:8080/JqueryTest/time.jsp",
   type:"post",
   dataType:"json",
   //async:true,
   async:false,
   success:function(obj)
   {
    alert("통신종료");
   },
    error: function(xhr,status,error){
     alert("실패");
    alert(error);
   }
  });
 $("#btn2").click(function(){
  alert("이메시지는 출력이 되면 안돼요");  
 });

 });
  
 });

</script>
</head>
 <body>
 <form id="form" name="form">
  <table>
   <tr>
   <td><span id="ajaxResult"></span></td>
   </tr>
  </table>
  
  <table>
  <tr>
  <td> <p>Jquery AJAX 속성 async</p>
&nbsp;&nbsp;&nbsp;&nbsp;$(document).ready(function(){</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$("#btn").click(function(){</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$.ajax({</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url:'http://localhost:8080/test/time.jsp',</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:'post',</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataType:'json',</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;async:true,</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;success:function(obj)</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("통신 종료");</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error:function(obj)</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("에러");</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</br>
&nbsp;&nbsp;&nbsp;&nbsp;}); </br>
&nbsp;&nbsp;&nbsp;&nbsp;$("#btn2").click(function(){</br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("이메시지는 출력이 되면 안돼요");</br>  
&nbsp;&nbsp;&nbsp;&nbsp;});</br>

   </td>
  </tr>
  </table>
  
 </form>
  <table id="table2">
  <tr>
  <td><a href="index.jsp">돌아가기</a></td>
  </tr>
  <tr>
  <td><input type="button" id="btn" value="클릭1"/></td>
  </tr>
  <tr>
  <td><input type="button" id="btn2" value="클릭2"/></td>
  </tr>
  </table>
 </body>
</html>

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함