2014-02-17 2 views
0

숫자가 있습니다. 내가 사용하지 않고 다른 페이지로이 값을 전달하는 데 필요한 window.locationURL을 사용하지 않고 매개 변수를 전달하는 방법

function sample(cID){ 
    var clg = ${param.clg}; 
    $.ajax({ 
     type : "post", 
     url : "sampleShow?clg="+clg+"&cID="+cID+"&level="+level, 
     dataType : "json", 
     cache : false, 
     beforeSend : function(xhr) { 
      xhr.setRequestHeader("Accept", "application/json"); 
      xhr.setRequestHeader("Content-Type", "application/json"); 
     }, 
     success : function(response) { 
      window.location= "cc" 
     }, 
     error : function(xhr) { 
      console.log("error"+xhr.status); 
     }, 
     complete : function() { 
     } 
    }); 
} 

이 내 컨트롤러 아약스 기능입니다 : 내가 CC 페이지에서 값을 얻을 필요가

@RequestMapping(value = "sampleShow", method = RequestMethod.POST) 
public @ResponseBody 
String showc(HttpServletRequest request,Model model) 
{ 
    model.addAttribute("ccID", request.getParameter("cID")); 
    model.addAttribute("clg", request.getParameter("clg")); 
    model.addAttribute("level", request.getParameter("level")); 

    return "{\"sucess\":\"true\"}"; 
} 

.

+0

왜 dataType : "json"을 설정 했습니까? json 데이터를 보내시겠습니까, 아니면 그냥 문자열 데이터입니까? –

+0

@sudarshan_SMD 그냥 문자열 데이터 – VSN

답변

0

귀하의 아약스 호출을 좋아한다 :

$.ajax({ 
     type : "post", 
     url : "sampleShow",    
     data : {clg: clg, cID: cID, level: level },    
     success : function(response) { 
      window.location= "cc" 
     }, 
     error : function(xhr) { 
      console.log("error"+xhr.status); 
     }, 
     complete : function() { 
     } 
    }); 

필요 없음을 dataType와 지정 : 당신이 JSON을 전송하지 않는 한, "json으로". 데이터는 '데이터'를 사용하여 전달됩니다. 자세한 내용은 jQuery.ajax()을 참조하십시오.

당신은 대신 jQuery.ajax의 게시, 속기 방법 jQuery.post()을 사용할 수 있습니다()

또한 what-is-the-difference-between-post-and-get에서 읽을하실 수 있습니다.

+0

귀하의 의견을 보내 주셔서 감사합니다 – VSN

관련 문제