【发布时间】:2017-11-16 19:04:39
【问题描述】:
我有一个博客网站,并在文章下方创建了一个评论面板。例子;用户名、邮件地址和评论...
我可以使用 ajax 添加这些字段,但无法确定评论是针对哪篇文章进行的。 那是输入..
<div class="form-group">
<%-- <label for="name" class="col-sm-2 control-label" style="color: #fff;">Name</label>--%>
<div class="col-sm-8">
<input type="text" class="form-control" id="t1" name="name" placeholder="Adınız" required tabindex="1">
</div>
</div>
<div class="form-group">
<%-- <label for="email" class="col-sm-2 control-label" style="color: #fff;">E-mail</label>--%>
<div class="col-sm-8">
<input type="email" class="form-control" id="t2" name="email" placeholder="E-mail Adresiniz" required>
</div>
</div>
<div class="form-group">
<%-- <label for="name" class="col-sm-2 control-label" style="color: #fff;">Message</label>--%>
<div class="col-sm-10">
<textarea id="t3" name="message" class="form-control" placeholder="Yorumunuz" rows="5" required></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-6">
<button type="submit" style="float: right;" class="btn btn-primary" onclick="ekle()">Gönder</button>
</div>
后面是commentAjax.aspx代码;
sqlBaglantisi baglan = new sqlBaglantisi();
string adsoyad, email, yorum, makaleID;
protected void Page_Load(object sender, EventArgs e)
{
makaleID = Request.QueryString["makaleID"];
adsoyad = Request.QueryString["adsyd"].ToString();
email = Request.QueryString["em"].ToString();
yorum = Request.QueryString["yrm"].ToString();
SqlCommand cmd = new SqlCommand("insert into Yorum (yorumAdSoyad, yorumEmail, yorumIcerik, yorumResim, makaleID) values('" + adsoyad.ToString() + "','" + email.ToString() + "','" + yorum.ToString() + "','/tema/yorumm.png')", baglan.baglan());
cmd.ExecuteNonQuery();
}
和js代码;
function ekle() {
var ad = document.getElementById("t1").value;
var mail = document.getElementById("t2").value;
var yorum = document.getElementById("t3").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "yorumAjax.aspx?adsyd=" + ad + "&em=" + mail + "&yrm="+yorum, false);
xmlhttp.send(null);
document.getElementById("t1").value = "";
document.getElementById("t2").value = "";
document.getElementById("t3").value = "";
alert("Mesaj Gönderildi");
由于无法获取 articleID 的值,我无法理解哪条评论来自哪篇文章。
【问题讨论】: