如何设置表单提交中的变量,以便在AJAX调用中使用


How to set a variable from form submit for use in AJAX call?

我有下面的表单:

  <form action="test.php" method="POST" onsubmit="loadXMLDoc(this.form); return false;">
  <input class="com" type="text" name="test" />
  </form>

代替"this。form",它的位置需要什么,以便将用户输入的文本传递给loadXMLDoc?

也:这是正确的语法,然后发送这个变量数据?

function loadXMLDoc($testVariable)
//standard ajax code..
xmlhttp.send("test=" + $testVariable);

表单可以通过名称引用输入元素作为属性。

loadXMLDoc(this.test.value);