我想从***电子邮件获取价值***输入文字后点击***提交* 按钮我不知道使用ajax然后使用php将数据发送到数据库
这是我的代码 enter image description here
<!--modal-->
<div id="pwdModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1 class="text-center">What's My Password?</h1>
</div>
<div class="modal-body">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="text-center">
<p>If you have forgotten your password you can reset it here.</p><br>
<div class="panel-body">
<fieldset>
<div class="form-group">
<input class="form-control input-lg" placeholder="E-mail Address" name="email" type="email" required id="email">
</div>
<input class="btn btn-lg btn-primary btn-block" value="Send My Password" type="submit">
</fieldset>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<div class="col-md-12">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
我假设您的电子邮件输入有id =&#34;电子邮件&#34; ... 并且在单击按钮示例时需要执行jquery代码:
<input type="text" id="email">
<button onClick="sendDatas()">Send</button>
<script>
function sendDatas()
{
$.ajax({
type:'post',
url :"page.php",
data: {'email' : $("#email").val()},
success: function(data) {
console.log("Sucess" + data);
});
},
error:function(exception){console.log(exception);}
});
}
</script>
你的page.php ......
$email = $_POST['email'];
答案 1 :(得分:1)
如果信息实际上是在模态弹出菜单中,那么我相信你需要研究jQuery委托(http://api.jquery.com/on/),因为动态内容没有被加载,它不会在DOM中找到它。