2010-07-22 10:34测试之前做的支付宝的例子
发现firfox提交时提交的时候 firebug总是提示:
document.alipaysubmit is undefined
post提交时间部分代码如下:
Response.Write("<form name='alipaysubmit' id='alipaysubmit' method='post' action='https://www.alipay.com/cooperate/gateway.do?_input_charset=utf-8'>");
Response.Write("<input type='hidden' name='service' value=" + service + ">");
Response.Write("<input type='hidden' name='partner' value=" + partner + ">");
// ...万恶的省略号
Response.Write("<input type='hidden' name='sign_type' value=" + sign_type + ">");
Response.Write("</form>");
Response.Write("<script>");
Response.Write("document.alipaysubmit.submit();");
Response.Write("</script>");
也就是说post传递是通过触发后台输出的表单的提交事件来传递提交的。
前台输出的代码是是正常的。先输出了表单,再输出提交的脚本。
可是提示document.alipaysubmit is undefined 则说明,在解释脚本时并不存在表单咯?
那么唯一可疑的就是后台输出的代码存在的位置。
代码位于页面的最顶端,即DOCTYPE 之前。在firebug中的解释,脚本处于head中
而表单存在于body中的最前端。
难道是说处于正常文档之外的代码会被自动进行整理?
新建了一个html页面,在doctype之前书写了一个div id为test
紧跟着插入js代码:
<script type="text/javascript">
document.getElementById("test").innerHTML = "asdfasdfsfd";
</script>
firebug报错document.getElementById("test") is null
js代码加到head中(不是title中),报一样的错。
放到body中,没有保错 运行正常。
放到html节点之后,没有报错,运行正常。
放到title中,没有报错,但运行没有效果了。