在测试.html在
{% extends 'base.html' %}
{% block extra_js %}
<script language="Javascript">
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}
function getquerystring() {
var form = document.forms['f1'];
var word = form.word.value;
qstr = 'w=' + escape(word); // NOTE: no '?' before querystring
return qstr;
}
function updatepage(str){
document.getElementById("result").innerHTML = str;
}
</script>
{% endblock %}
{% block main1 %}
<form name="f1">
<p>word: <input name="word" type="text">
<input value="Go" type="button" onclick='JavaScript:xmlhttpPost("/site_media/rt.py")'></p>
<div id="result"></div>
</form>
{% endblock main1 %}
rt.py公司
^{pr2}$所以当我点击Go按钮时,我想要在div标记中得到值10。但是输出是 def ret():i=10返回i
刚刚读过rt.py公司并显示在网页上。在
你期待什么?字符串
10
是否出现在页面中?在不会,因为您有以下问题:
现在,我怀疑您使用Django,所以这可能不是web服务器的问题,而是配置问题。在本例中,请遵循与您的Django版本相对应的Django tutorial,您将了解到您必须配置一个URL,将其映射到一个应用程序并在那里编写响应。在
如果不使用Django,只需修复web服务器和python代码,就像我(很快)解释的那样。在
相关问题 更多 >
编程相关推荐