MVC 스프링 컨트롤러가 있습니다. 페이지로드시이 아약스를 호출합니다.ajax 호출 MVC 스프링 컨트롤러를 찾을 수 없음 오류
$.ajax({
type: "get",
url: 'custom/Service',
data: "note1=" + "11",
dataType: "json",
async: false,
success: function() {
alert("1");
},
error:function (xhr, ajaxOptions, thrownError){
if(xhr.status == 200 && xhr.statusText == 'parsererror'){
window.location.reload();
} else {
alert(xhr.status+","+xhr.statusText);
alert(thrownError);
}
}
});
내 컨트롤러는 다음과 같습니다
@RequestMapping("/custom")
public class CustomController {
@RequestMapping(value="/Service", method=RequestMethod.GET)
public String Service(
@RequestParam("note1") String note1,
HttpServletRequest request, HttpServletResponse response, Locale locale,
Model model) {
String result = custom.Service(note1, request, response);
System.out.println("result: " + result);
return result;
}
}
아웃 된 풋 컨트롤러의 콘솔에서 올바른 것입니다. 하지만 "찾을 수 없음"오류가 발생합니다. 다음은 개발자 도구 오류입니다. "MySite/custom/Service? note1 = 11"404 (찾을 수 없음)를 가져옵니다. 뭐가 잘못 되었 니?
경로가 정확합니다. 콘솔에서 출력을 볼 수 있기 때문에. 나는 프로젝트에서 다른 아약스 호출에 대한 경로를 사용하고 작동합니다. – Mark
결과가 틀림 없습니다. 맞습니까? jsp 이름이어야합니다. –
난 그냥 클래스를 생성하고이 같은 점에서 모든 매핑을 넣어 : @RequestMapping을 ("/ 사용자 정의") 공용 클래스 CustomController {\t @RequestMapping (값 = "/ 서비스", 방법 = RequestMethod.GET) \t 공공 문자열 ServiceType 자리를 ( \t \t \t @RequestParam ("주") 문자열 주, \t \t \t HttpServletRequest의 요청 HttpServletResponse를 응답 로케일 로케일 \t \t \t 모델 모델) { \t \t 문자열 결과 = custom.Service (주 요청, 응답); \t System.out.println ("result :"+ result); \t 반품 결과; } – Mark