简体   繁体   English

如何设置表单提交中的变量以用于AJAX调用?

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

I have the below form: 我有以下表格:

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

Instead of "this.form", what would need to be in its place so that the text input by the user is passed to loadXMLDoc? 代替“ this.form”,将需要什么来将用户输入的文本传递给loadXMLDoc?

Also: is that the correct syntax to then send this variable data? 另外:发送该变量数据的语法是否正确?

function loadXMLDoc($testVariable)

//standard ajax code..

xmlhttp.send("test=" + $testVariable);

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

loadXMLDoc(this.test.value);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM