问题遇到的现象和发生背景
Ajax没有任何反应,点击发表评论按钮和点赞,ajax没有任何反应,不会弹出回调函数提示,调试的时候发现根本没有触发ajax,不知道为什么
问题相关代码,请勿粘贴截图
视图界面
@model WebWEI.Models.Photograph
@{
ViewBag.Title = "picDetails";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Details</title>
<link href="~/Css/global .css" rel="stylesheet" />
<script src="~/Scripts/ckeditor/ckeditor.js"></script>
<script src="~/Scripts/ckeditor/config.js"></script>
<script src="~/Scripts/jquery-3.4.1.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
</head>
<body>
<div id="Home">
<div id="homebox">
<div id="leftbox">
<div id="imgbox">
@{
var item = Model.PhotographUrl;
}
<img src="@item" style="width:400px;height:300px;" />
@*<img class="sample2" data-img2blob="~/Images/我的帖子.png" />*@
</div>
<div id="tupianxiangqing">
<div style="width:500px;height:50px; padding-left:80px;color:black;margin-top:20px"><span>发布时间:</span>@Html.DisplayFor(model => model.ShootTime)</div>
<div style="width: 500px; height: 50px; padding-left: 80px; color: black; margin-top: -20px"><span>图片ID:</span>@Html.DisplayFor(model => model.photographId)</div>
<div style="width: 500px; height: 50px; padding-left: 80px; color: black; margin-top: -20px"><span>图片规格:</span>@Html.DisplayFor(model => model.Specifications)</div>
<div style="width: 500px; height: 50px; padding-left: 80px; color: black; margin-top: -20px"><span>图片介绍:</span>@Html.DisplayFor(model => model.photographIntroduction)</div>
<div style="width: 500px; height: 50px; padding-left: 80px; color: black; margin-top: -20px"><span>图片价格:</span>@Html.DisplayFor(model => model.photographValue)</div>
</div>
<div id="xiabox">
<div id="button1">
<a href='@Url.Action("Download", "Photographs", new { fileName =item})'>
立即下载
</a>
</div>
<div id="gou"><button id="button2"> 购物车</button></div>
</div>
</div>
@{
WebWEI.Models.post post = ViewBag.Post
as WebWEI.Models.post;
WebWEI.Models.UserInfo user = ViewBag.UserInfo
as WebWEI.Models.UserInfo;
}
<div id="rightbox">
<div id="toutitle">
@if (user!= null)
{
string uname = user.userName;
string headportrait = user.userHeadPortrait;
<div id="touxiang">
<a href="/User/PersonalCenter" target="_blank">
<img src=@headportrait class="headportrait" />
</a>
</div>
}
<div id="posttitle">@post.postTitle</div>
</div>
<div id="postcontent">@post.postContent</div>
<div id="zanlunnum">
@*<div id="zannum"><span>点赞数</span>@post.likesNums</div>*@
<div style="float: left;width: 45px;padding: 5px;font-size: 17px;">
@Ajax.ActionLink("点赞", "Carrypost", "User", new { id = post.postId }, new AjaxOptions
{ HttpMethod = "get", UpdateTargetId = post.postId, OnSuccess = "LikeSuccess" })
</div>
<div id="@post.postId" style="width: 60px;float: left;font-size: 17px;">
@Html.Action("PostZanNum", "User", new { id = post.postId })
</div>
<div id="lunnum"><span>评论数</span>@post.commentsNums</div>
</div>
<div id="lun"></div>
</div>
</div>
<div id="L">
<div id="pinglun">
@using (Ajax.BeginForm("AddpostpicComment", "posts", new AjaxOptions
{
HttpMethod = "post",
UpdateTargetId = "result",
OnSuccess = "Comment"
}))
{
<input type="hidden" name="postId" id="" value="@Model.postId" />
<textarea name="comment" id="editor"></textarea>
<script>
var editor = CKEDITOR.replace('editor');
</script>
<br />
<input type="submit" value="发表评论" />
}
</div>
<div id="result">
@Html.Action("PostpicComment", "posts", new { id = Model.postId })
@*@{Html.RenderPartial("PostpicComment", ViewBag.Comment as IEnumerable<WebWEI.Models.Comment>);}*@
</div>
</div>
</div>
@*<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.photographId }) |
@Html.ActionLink("Back to List", "Index")
</p>*@
@section scripts{
<script>
function Comment(data) {
if (data == "Login") {
alert("请先登录!");
window.location.href = '/Home/Login';
}
else if (data == "Fault") {
alert("评论失败!");
window.location.reload();
}
else {
$("#newcomment").html(data);
alert("评论成功!");
}
}
function deletecomment(id) {
$.ajax({
url: "/ShiCi/DeleteShiCiComment",
type: "post",
data: {
commentid: id,
},
success: function (data) {
if (data == "suc") {
var comment = document.getElementById(id);
comment.style.display = "none";
alert("已删除评论!");
window.location.reload();
}
else {
alert("删除评论失败!");
}
}
});
}
</script>
}
</body>
</html >
运行结果及报错内容
ajax没有反应
我的解答思路和尝试过的方法
可能没有引入相关script