반응형

AJAX 코드 

  • success : url 호출에 대한 응답 코드가 2xx인 경우

기본적으datastatusText, jqXHR 세 개의 파라미터가 있다.

 

  • error : url 호출에 대한 응답 코드가 2xx가 아닌 경우

error의 경우도 jqXHR, textStatus, errorThrown 세 개의 파라미터를 가진다.

jqXHR : 서버에서 responseEntity에 담아서 보낸 응답 메시지로, 데이터 내부에서 응답 텍스트와 응답 코드를 확인할 수 있다.

errorThrown :  응답코드의 텍스트 이름이라고 한다.(근데 나는 안 뜸)

 $.ajax({
 	type: "post",
	url : "http://localhost:8080/donwnload",
	headers: {'Content-Type': 'application/json'},
	data : JSON.stringify(obj),
                    
	success : function (data, statusText, jqXHR){
		console.log(data); //응답 body부 데이터
		console.log(statusText); //"succes"로 고정인듯함
		console.log(jqXHR);
	},
                    
	error : function (jqXHR, textStatus, errorThrown){
		console.log(jqXHR);  //응답 메시지
		console.log(textStatus); //"error"로 고정인듯함
		console.log(errorThrown);
	}
})

 

error function의 jqXHR

  • responseText : ResponseEntity 응답 메시지로 보낸 텍스트 ( jquery 1.4.x 버전은 XMLHttpRequest로 표시)
  • status : 응답코드

 


참고

 

jQuery.ajax() | jQuery API Documentation

Description: Perform an asynchronous HTTP (Ajax) request. The $.ajax() function underlies all Ajax requests sent by jQuery. It is often unnecessary to directly call this function, as several higher-level alternatives like $.get() and .load() are available

api.jquery.com

 

반응형
반응형

 

spring 프레임 워크 사용

위와 같이 컨트롤러에서 update 실행하고 콜백함수도 정상값, DB업데이트도 되는데

자꾸 에러로 넘어가서 수정실패가 뜨는거임 ㅠ 

위는 jsp 쪽 ajax 코드.

error와 success의 기준이 뭘까..

DB 업데이트는 되는데 error 가 뜨는경우 리턴되는 dataType이 맞지 않아 그렇다고 함.

컨트롤러에서 콘솔로 찍힌 값을 보면 

JSON이 맞는데

return 할 때 문제가 있었던 거임 

@ResponseBody 를 붙이지 않아서 그렇슴.

 

@ResponseBody * return 값에 prefix와 suffix가 붙지 않음
* ajax 호출 시 정상적인 json 데이터 반환을 위해 사용함

 

반응형

+ Recent posts