2013-10-29 4 views

답변

3

문제는 매우 일반적이지만, 여기에 한 가지 방법이다 하고있어.

 $.ajax({type: 'POST', 
       url: '/fetch_data/',       // some data url 
       data: {param: 'hello', another_param: 5},  // some params 
       success: function (response) {     // callback 
        if (response.result === 'OK') { 
         if (response.data && typeof(response.data) === 'object') { 
          // do something with the successful response.data 
          // e.g. response.data can be a JSON object 
         } 
        } else { 
         // handle an unsuccessful response 
        } 
       } 
       }); 

그리고 장고보기이 같은 것 : :이처럼 AJAX 호출하기 위해 jQuery를 사용할 수

def fetch_data(request): 
    if request.is_ajax(): 
     # extract your params (also, remember to validate them) 
     param = request.POST.get('param', None) 
     another_param = request.POST.get('another param', None) 

     # construct your JSON response by calling a data method from elsewhere 
     items, summary = build_my_response(param, another_param) 

     return JsonResponse({'result': 'OK', 'data': {'items': items, 'summary': summary}}) 
    return HttpResponseBadRequest() 

많은 세부 사항이 분명 생략되어 있지만, 당신은으로 사용할 수 있습니다 지침.

+0

감사합니다. 코드가 이해하는 데 도움이됩니다. – Jmint

1

두 가지 방법 :

  1. Ajax 요청보기에
  2. 당신의 값이 쿼리 parametr에게 있습니다 새로운 URL에
  3. 리디렉션 사용자
+0

아약스 사용에 대한 예가 있습니까? 나는 새로운 것 – Jmint

+2

@ Jmint : 그것은이 질문의 범위 밖이다 (그리고이 사이트는 정직해야한다). jquery에 익숙하다면 http://www.sitepoint.com/ajax-jquery/에서 jquery AJAX를 배우기 시작하십시오. Google은 바닐라 자바 ​​스크립트 AJAX에 대한 자습서를 찾도록 도와 줄 것입니다. – hellsgate

관련 문제