表单提交第一次失败,并在刷新页面时工作
Form submit fails the firstime and works upon refreshing the page
我正在运行一个django web应用程序,当我第一次提交表单失败时,我需要刷新并再次提交表单以在其中发送数据,或者在web浏览器上进行反向转发。我正在使用一个javascript程序(editarea)在文本区域上自动着色代码
这是我的HTML文件:
<html>
<head>
<title>Test</title>
<script language="javascript" type="text/javascript" src="/static/edit_area/edit_area_full.js"></script>
<script type="text/javascript">
function load() {
var combo = document.getElementById('selSeaShells1').value;
editAreaLoader.init({
id: "textarea_1" // textarea id
, syntax: combo // syntax to be uses for highgliting
, start_highlight: true // to display with highlight mode on start-up
});
}
</script>
</head>
<body onload="load();">
<form id="codeid" method="post" enctype="application/x-www-form-urlencoded" name="code" action="DestinationAddress/function">
<h3>Choose a language</h3>
<select name="sellang1" id="selSeaShells1" onchange="load();">
<option value="python">Python</option>
<option value="perl">Perl</option>
<option value="sql">SQL</option>
<option value="cpp">C++</option>
<option value="c">C</option>
<option value="java">Java</option>
<option value="css">Css</option>
</select>
<br>
<textarea id="textarea_1" name="content" cols="80" rows="15" type="text"></textarea>
<input id="thebutton" type="button" value="Submit" onclick="document.forms.codeid.submit();" />
</form>
</body>
</html>
这里是视图.py:
def function(request):
encoded_data = urllib.urlencode(request.POST)
url=urllib2.urlopen('http://webappAddress:8000/function/?' + encoded_data)
tml= url.read()
return HttpResponse(tml)
您的javascript失败
var combo=document.getElementById('selSeaShells1').value;
Combo将是未定义的,因为您在页面加载完成之前调用了load()。
我会使用jquery并这样做:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> //download and get a local copy of jquery don't use googles.***<script>
$(document).ready(function() {
load();
});
function load()
{
var combo = $('#selSeaShells1 option:selected).val();
editAreaLoader.init({
id : "textarea_1" // textarea id
,syntax: combo // syntax to be uses for highgliting
,start_highlight: true // to display with highlight mode on start-up
});
}
</script>
删除body标记上的onload="load();"
这将在页面加载后获得所选内容。
相关文章:
- 刷新后,setTimeout将工作或不工作
- .html()不会'页面更改或刷新时无法工作
- AngularJS控制器没有'第一次刷新页面后无法工作
- .addClass不工作(刷新时被删除)
- Javascript don'刷新页面后无法工作-为什么
- Kml层在刷新后工作正常,但给定typeError:无法读取属性getMap.第一次加载时
- jQuery AJAX刷新没有'不能在iPhone上工作
- Javascript在刷新后停止工作
- 页面刷新时脚本无法正常工作
- 为什么 jquery toggle() 方法在页面不刷新的情况下无法正常工作
- ngCookie在我刷新页面后无法正常工作
- Angular + requireJS:快速刷新页面会导致页面在 Chrome 中停止工作
- Jquery 日期选择器仅在页面刷新后工作
- 将公司名称绑定到更新面板中的下拉列表,自动完成文本框工作,但每次页面刷新时
- 防止刷新后返回不工作
- 轮播在初始重定向时中断,但在刷新时工作正常
- Javascript仅在第一次刷新后工作
- Javascript在页面刷新后工作,不知道解决方案
- JQuery 函数在页面加载时未触发,它仅在我刷新页面或再次重新访问同一页面后才能工作
- Rails 应用程序 - jQuery Document.ready在单击链接时不调用,但在新选项卡中打开或刷新时工作