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

时间:2013-05-31 22:10:55

标签: php javascript ajax

我有以下表格:

  <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);

1 个答案:

答案 0 :(得分:1)

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

loadXMLDoc(this.test.value);