2013-10-29 55 views

回答

3

的問題是相當普遍的,但這裏的一種方式正在做。你可以使用jQuery來讓你的AJAX調用是這樣的:

 $.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 
        } 
       } 
       }); 

而且你的Django的看法是這樣的:

許多細節顯然這裏省略了,但你可以使用這個作爲指南。

+0

謝謝你,你的代碼可以幫助我理解 – Jmint

1

兩種方法在這裏:

  1. Ajax請求到您的視圖
  2. 將用戶重定向到新的網址,讓你的價值是查詢parametr
+0

你有任何使用Ajax的例子嗎?我是新的 – Jmint

+2

@Jmint:這是與這個問題的範圍(和本網站說實話)。如果您熟悉jquery,請從http://www.sitepoint.com/ajax-jquery/開始學習jQuery AJAX。谷歌將幫助你找到與香草的AJAX教程javascript – hellsgate

相關問題