0

我正在尝试创建一个非常简单的帖子表单,它将一个电子邮件地址添加到我的数据库中,然后将提交按钮更改为“谢谢”。我遇到了一些问题,我不知道问题出在我的 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);
}
}
4

1 回答 1

0

我不知道该行<button id="subscribe-submit" type="submit" class="btn btn primary">Thankyou</button>应该做什么,但如果你想更改按钮的文本,你可以这样做:$("#subscribe-submit").html("Thank you");

于 2013-10-28T12:13:54.540 回答