简体   繁体   English

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

[英]how can I update value of input text via ajax?

I want to have 我希望有

  • an input text box that I can 我可以输入文本框
  • update its value with AJAX call ('get current revision') and then 使用AJAX调用('获取当前版本')更新其值,然后
  • another button ( "update code base" ) to make another AJAX call the value in the text box 另一个按钮(“更新代码库”)使另一个AJAX调用文本框中的值

I do not know how to combine all this together. 我不知道如何将所有这些结合在一起。

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

I would like to use only javascript not jQuery 我想只使用javascript而不是jQuery

<form action="upgage.php">
  <input type="submit" id="revision"/> <input type="text" id="passedValue" value="" /><br />
  <input type="submit" value="update" />
</form>

now in jQuery: 现在在jQuery中:

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

});

Hope I understood you correctly :P 希望我理解你:P

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

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

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