<▼시작▼ | 파일명 :jq11.html >
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
$(document).ready(function(){
$("#btn1").on("click", aa);
});
function aa(){
//alert("a");
$.ajax({
type:"get",
url:"jq11.jsp", // 실제로는 "상대방 IP 주소 경로/jq11.jsp"가 되어야 함
dataType:"jsonp",
jsonp:"callback",
success:function(data){
var res = data.datas;
//alert(res + " " + res.length);
var imsi = "";
$(res).each(function(ind, entry){
imsi = "<div>" + entry.no + " - "+entry["name"] + "</div>";
$("#disp").append(imsi);
});
},
fail :function(){
alert("읽기 실패");
}
});
}
</script>
</head>
<body>
** 다른 도메인 서버의 json 자료 읽기 **<br>
<button id ="btn1">test</button>
<hr>
<div id ="disp"></div>
</body>
</html>
<▲종료▲ | 파일명 : jq11.html >
<▼시작▼ | 파일명 : jq11.jsp >
<%@ page language="java" contentType="text/plain; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String funcName = request.getParameter("callback");
if(funcName !=null){
%>
<%=funcName %>(
{"datas":
[
{"no":"10","name":"에스프리터"},
{"no":"10","name":"홍두깨"},
{"no":"10","name":"고길동"}
]
}
);
<%
}
%>
<▲종료▲ | 파일명 : jq11.jsp >
|
[ 결과 이미지]
|
라즈베리파이에 Mariadb 설치하기 #2 (0) | 2018.05.09 |
---|---|
jQuery - 다른 도메인 서버의 json 자료 읽기 예제 (0) | 2018.03.08 |
jQuery - JSON 데이터를 호출하고 검색 건수 확인 예제 (0) | 2018.03.08 |
jQuery - Ajax 전담 메소드를 활용하여 json,xml 읽기 예제 (0) | 2018.02.28 |
jQuery - Ajax로 자료 읽기 예제 (0) | 2018.02.28 |
jQuery - jQuery 기본 예제 #8 (0) | 2018.02.27 |
jQuery - jQuery 기본 예제 #7 (0) | 2018.02.27 |
댓글 영역