javascript 未捕获的类型错误:无法读取未定义的属性“提交”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23205706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught TypeError: Cannot read property 'submit' of undefined
提问by Priyanka
This is the html when I inspect element in chrome
这是我在 chrome 中检查元素时的 html
<html>
<head>
<title>Please Wait</title>
<link rel="shortcut icon" href="images/ajax-loader1.gif" type="image/x-icon">
<style type="text/css">
</style>
</head>
<body onload="autoSubmit();" cz-shortcut-listen="true">
<div>
<p class="header">Please Wait... Your Payment Request is being processed......</p>
<p class="image_style">
<img src="images/ajax-loader.gif">
</p>
<ul>
<li>This is a secure payment gateway using 256 bit SSL encryption</li>
<li>When you submit the transaction, the server will take about 1 to 5 seconds to process, but it may take longer at certain times </li>
<li>Please do not press "Back" or "Refresh" buttons</li>
</ul>
</div>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Card Request</title>
<script type="text/javascript">
function autoSubmit()
{
document.card_processing.submit();
}
</script>
</body>
</html>
I'm posting some values to a url given and from there it is redirected using the below auto-submitting. Sometimes this page wont load sometimes it does.What is the problem?
我将一些值发布到给定的 url,并从那里使用以下自动提交重定向。有时这个页面不会加载有时会加载。这是什么问题?
This is what I get from console
这是我从控制台得到的
Uncaught TypeError: Cannot read property 'submit' of undefined
回答by ReNiSh A R
replace your code by adding a form:
通过添加表单来替换您的代码:
<body onload="autoSubmit();" cz-shortcut-listen="true">
<form name="card_processing">
<div>
<p class="header">Please Wait... Your Payment Request is being processed......</p>
<p class="image_style">
<img src="images/ajax-loader.gif">
</p>
<ul>
<li>This is a secure payment gateway using 256 bit SSL encryption</li>
<li>When you submit the transaction, the server will take about 1 to 5 seconds to process, but it may take longer at certain times </li>
<li>Please do not press "Back" or "Refresh" buttons</li>
</ul>
</div>
</form>
but i think you need a redirection page which shows a progress status:
但我认为您需要一个显示进度状态的重定向页面:
for achieving that there is no need for a form or any scripting on body load
为了实现这一点,不需要表格或任何关于身体负荷的脚本
use meta refresh tag:
使用元刷新标签:
<meta http-equiv="refresh" content="5; ,URL=<redirect_url>">
this will redirect the page after 5 seconds...
这将在 5 秒后重定向页面...
回答by Radin Reth
Because you are dealing with javascript to submit your form:
因为您正在处理 javascript 以提交表单:
So it's wisely to waituntil your script is loaded.
因此,明智的做法是等到您的脚本加载完毕。
document.addEventListener("DOMContentLoaded", function(){
// Handler when the DOM is fully loaded
});