我正在尝试创建一个非常简单的帖子表单,它会在我的数据库中添加一个电子邮件地址,然后将提交按钮更改为“谢谢”。我有一些问题,我不知道问题是我的AJAX代码,还是部分页面,它将它添加到数据库。
这是我的代码:
形式:
<div id="myform">
<form action=""name="subscribe-form">
<h5>Subscribe to our “New Property” newsletter.</h5>
<div class="controls">
<input name="subscribe-email" id="subscribe-email" type="email" class="span4" placeholder="Email">
</div>
<p style="color: #fff">You can unsubscribe at any time if you don’t find it useful and informative.</p>
<div class="controls">
<button id="subscribe-submit" type="submit" class="btn btn-primary">Subscribe</button>
</div>
</form>
</div>
<script type="text/javascript">
$(function(){
$('#subscribe-submit').click(function(){
var dataString = 'email='+ subscribe=email;
$.ajax({
type: "POST",
url: "~/Partials/NewsletterSubscription.cshtml",
data: dataString,
success: function (data) {
$('#myform').html(data);
<button id="subscribe-submit" type="submit" class="btn btn-primary">Thankyou</button>
}
return false;
});
});
});
</script>
部分:
@{
layout = null;
if(IsPost){
var db = Database.Open("StayInFlorida");
var sql = "INSERT INTO NewsletterSubscription (Email, CreatedDate) VALUES (@0, GetDate())";
var email = Request["subscribe-email"];
db.Execute(sql, email);
}
}
答案 0 :(得分:0)
我不知道行<button id="subscribe-submit" type="submit" class="btn btn primary">Thankyou</button>
应该做什么,但是如果你想改变按钮的文本,你可以这样做:$("#subscribe-submit").html("Thank you");