Javascript 如何在post请求之前设置输入值?
如何在post请求之前设置输入值 我想定下来Javascript 如何在post请求之前设置输入值?,javascript,php,ajax,Javascript,Php,Ajax,如何在post请求之前设置输入值 我想定下来 document.getElementById('input_id').value = "true"; 在发送ajax帖子之前 设定 document.getElementById('input_id').value = "false"; 发送ajax成功后 但不是工作,我怎么办 $('#loading').show(); document.getElementById('input_id').value = "true"; timer = se
document.getElementById('input_id').value = "true";
在发送ajax帖子之前
设定
document.getElementById('input_id').value = "false";
发送ajax成功后
但不是工作,我怎么办
$('#loading').show();
document.getElementById('input_id').value = "true";
timer = setTimeout
(function ()
{
$.ajax({
url: 'somepage.php',
type: 'POST',
data: $('#fid').serialize(),
cache: false,
success: function(response)
{
document.getElementById('input_id').value = "false";
$("#loading").fadeOut("slow");
$('#demoajax').append(response);
}
});
}, 2000
);
您的代码应该完全符合您的要求。请参阅JS控制台输出。我认为元素不存在,或者它不是ID而是类名 此外,您应该以jQuery的形式编写所有代码,这样更容易;-)
你的html是什么,输入id是否存在?是的,我已经用开发者工具调试过了?你确定你得到了成功的响应吗?如果你把它放在ajax请求之前,
console.log(document.getElementById('input\u id').value)
会显示什么?Maxxi,加载图像显示,但input id input\u id中没有数据
$('#loading').show();
$("#input_id").val("true");
timer = setTimeout(function (){
$.ajax({
url: 'somepage.php',
type: 'POST',
data: $('#fid').serialize(),
cache: false,
success: function(response){
$("#input_id").val("false");
$("#loading").fadeOut("slow");
$('#demoajax').append(response);
}
});
}, 2000);