Javascript 如何通过ajax更新输入文本的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5149080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:50:43 来源:igfitidea点击:
how can I update value of input text via ajax?
提问by Radek
I want to have
我希望有
- an input text box that I can
- update its value with AJAX call ('get current revision') and then
- another button ( "update code base" ) to make another AJAX call the value in the text box
- 一个输入文本框,我可以
- 使用 AJAX 调用更新其值(“获取当前修订版”),然后
- 另一个按钮(“更新代码库”)使另一个 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
采纳答案by Marc Abramowitz
<script>
document.getElementById('getValueButton').onclick = function() {
document.getElementById('revisionTextField').value = getRevisionViaAjax();
}
</script>
回答by Uku Loskit
<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