【问题标题】:how to implement ajax in django app?如何在 django 应用程序中实现 ajax?
【发布时间】:2011-07-15 16:35:08
【问题描述】:

我的问题与

中提到的类似

use of ajax in django problem with the code

我尝试了给出的解决方案,但我仍然没有得到响应值。下面是我的代码

chkAjax.html
------------

<html>  
<head>  
<script>   
function chkAjax(form)  
{        
    var xmlhttp;
    if (window.XMLHttpRequest)
      {
         xmlhttp=new XMLHttpRequest();
      }
    else
      {
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                alert(xmlhttp.responseText);    
                document.getElementById("t1").innerHTML=xmlhttp.responseText;
            }
      }
    xmlhttp.open("GET","/sign?text="+form.text1.value,true);
    xmlhttp.send();
}
function DoNav(theUrl,form)
{
      theUrl = theUrl + '?text=' + form.text1.value;
      document.location.href = theUrl;
}
</script>  
</head>
<body>   
<form method="get" action="">  
    <input type="text" name="text1" id="t1" onkeyup = 'chkAjax(this.form)'/>  
</form>
</body>
</html>

下面是我的处理程序的代码

from django.http import HttpResponse  
c=self.request.get('text')  
c=c + "b"  
self.response.write("hi")

使用 alert() 我知道我收到了响应但值为空,所以请帮我解决这个问题

【问题讨论】:

  • 大家好,我已经解决了这个问题,所以不需要回复所有人
  • 关闭问题或找到最佳答案 ;)
  • 如何关闭队列??我不知道

标签: javascript python ajax django google-app-engine


【解决方案1】:

在 django 中查找 ajax 的最佳示例

【讨论】:

    猜你喜欢
    • 2011-02-18
    • 2021-01-05
    • 2011-07-18
    • 2014-05-26
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多