我有两个文件与php和html。这是我的A.php文件中的基本信息
<div class="col-md-8">
<input type="email" class="form-control" placeholder="Ingresar Número de Nota" id="idnote" name="idnote">
</div>
<button type="button" class="btn btn-primary" id="notes">Enviar</button>
当用户单击按钮时,它将在js中调用一个函数。
$(document).ready(function() {
var formData = {
'id' : $('input[name=idnote]').val()
};
$.ajax({
type : 'POST',
url : '../consults/findnote.php',
data : formData,
dataType : 'json',
encode : true
})
.done(function(data) {
//Going to findnote.php and keeping formData
//This findnote.php contains a completely different design but I need the first value to make some changes for the user.
})
});
});
问题是在ajax之后,我的网页将不会找到findnote.php,而只是发送值,而且我需要显示findnote.php,我知道我是否使用
event.preventDefault();
Ajax将阻止重新加载,但是我没有使用它。
有办法吗?创建window.location后如何保留值?(因为如果在成功调用后调用文件,我会丢失值)我应该只尝试php吗?(它是一个选择)
为什么不使用纯HTML?
<form action="../consults/findnote.php" method="POST">
<div class="col-md-8">
<input type="email" class="form-control" placeholder="Ingresar Número de Nota" id="idnote" name="id">
</div>
<button type="submit" class="btn btn-primary" id="notes">Enviar</button>
</form>
刚刚添加了表单标签并编辑了输入名称,因为它符合您的函数结果。
“问题在于,在ajax之后,我的网页将不会找到findnote.php,而只是发送值”,这基本上就是ajax用于的目的:)
使用ajax,可以根据需要将结果附加到当前页面(您不在代码中。仅发送数据)。
另一个带有表单标签的解决方案(上面的解决方案)将结果加载为新页面,就像经典链接一样。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句