Jquery 在输入字段中插入Ajax结果
我有以下代码:Jquery 在输入字段中插入Ajax结果,jquery,ajax,Jquery,Ajax,我有以下代码: $('body').on("click", '.saveimage', function () { $.ajax({ type: "post", url: "save.php", data: foo.crop(570, 765, 'png') }).done(function(data) { $('#ajaxDiv').html(data); }); }
$('body').on("click", '.saveimage', function () {
$.ajax({
type: "post",
url: "save.php",
data: foo.crop(570, 765, 'png')
}).done(function(data) {
$('#ajaxDiv').html(data);
});
});
当我从save.php获得结果时,我需要将其以其他形式插入到隐藏的输入字段中
例如:
<div class="ajaxDiv">
<form method="post">
<input type="hidden" value="result from ajax">
<input type="submit" value="ok">
</form>
</div
首先,您应该给隐藏的输入一个id,以便您可以选择它:
<input type="hidden" value="" id="result">
非常感谢!它起作用了!你能帮我回答其他问题吗?是否可以在ajax返回#结果值之前隐藏submit按钮?是的,使用display:none
在CSS中隐藏submit按钮,然后在done()
处理程序中添加对元素的.show()
的调用。
.done(function(data) {
$('#result').val(data);
});