自动POST文档创建

时间:2010-05-21 13:29:14

标签: javascript html http

在HTML文档中,我希望有一个(如果可能:不可见)表单,一旦创建文档或在s秒内将文本输入字段的内容POST到我的服务器。该文档是通过javascript打开创建的。

我该怎么做?

3 个答案:

答案 0 :(得分:1)

无论你想做什么:)你可以随时用javascript提交表格:

document.form_name.submit();

假设您想在页面加载后立即提交表单,您可以这样做:

<head>
<script type="text/javascript">
window.onload = function(){
  document.form_name.submit();
};
</script>
</head>

答案 1 :(得分:0)

你可能想在这里使用一些AJAX魔法。

您可以通过使用POST请求来获取客户端将某些数据传送到服务器来实现此目的。

我建议您阅读此jQuery AJAX Tutorial

答案 2 :(得分:0)

XMLHttpRequest对象(负责Google地图和Gmail等漂亮AJAX之类的对象)允许从浏览器与您的服务器进行无形通信。我建议使用一些AJAX库来涵盖跨浏览器的差异。最流行的是Jquery,它允许这样的代码:

$.post('/path/to/script.php', {
  "key": "Value",
  "anotherkey": "it's value"
}, function (dat){
  //this function will be called when it is succesful
  //the variable dat is populated witht he server's response.
});

这样可以与浏览器进行简单的无缝通信。