1. 서블릿이름 *servlet*.xml
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class = "org.springframework.http.converter.StringHttpMessageConverter">
<property name = "supportedMediaTypes">
<list>
<value>text/plain;charset=utf-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
2. Controller
@ResponseBody // 중요함
@RequestMapping(value = "/board/boardViewAjax.do") //맵핑될 주소
public String gogogo(ModelMap model, SessionStatus status)
throws Exception {
String test = "권오범";
System.out.println("gogogogo: ");
return test;
}
3. jsp
<script type="text/javascript" src="<c:url value='/js/jquery.js'/>"></script>
<script>
$(function(){
$('#test').click(function(){
// $,post('http://localhost:8090/lab103/board/boardViewAjax.do', 'data', function(){ alert("전송완료");
// });
//얘는 왜안되는지 이유 모르겠음..; 간단한건데
$.ajax({
type : "POST",
url: "http://localhost:8090/lab103/board/boardViewAjax.do",
success: function(data) {
if(data != null) {
$('#text').val(data);
} else {
alert("failed");
}
}
});
});
});
</script>
댓글 없음:
댓글 쓰기