如何通过ajax更新输入文本的值?

Rad*_*dek 7 javascript ajax

我希望有

  • 我可以输入文本框
  • 使用AJAX调用('获取当前版本')更新其值,然后
  • 另一个按钮("更新代码库")使另一个AJAX调用文本框中的值

我不知道如何将所有这些结合在一起.

<form action="upgage.php">
  revision <input type="text" name="revision" value="" /><br />
  <input type="submit" value="update code base" />
<input type="submit" value="get current revision" />

</form>
Run Code Online (Sandbox Code Playgroud)

我想只使用javascript而不是jQuery

Uku*_*kit 7

<form action="upgage.php">
  <input type="submit" id="revision"/> <input type="text" id="passedValue" value="" /><br />
  <input type="submit" value="update" />
</form>
Run Code Online (Sandbox Code Playgroud)

现在在jQuery中:

$("#revision").click(function(event) {
  event.preventDefault();
   $.post("/my/url/", function(data) {
      $("#passedValue").val(data);
   });

});
Run Code Online (Sandbox Code Playgroud)

希望我理解你:P


Mar*_*itz 6

<script>
    document.getElementById('getValueButton').onclick = function() {
        document.getElementById('revisionTextField').value = getRevisionViaAjax();
    }
</script>
Run Code Online (Sandbox Code Playgroud)