【发布时间】:2018-08-02 06:19:20
【问题描述】:
我正在使用图像映射,我想在单击任何坐标时在弹出窗口中显示数据,然后在弹出窗口中显示数据。如果我在 jQuery 中编写代码,如何在弹出窗口中显示数据?
下面是我的 HTML、jQuery 和 C# 代码。数据是从数据库中获取的,应该显示在弹出窗口中。 C# 代码和 jQuery 代码工作正常,但是如何在弹出窗口中显示数据?
HTML
<img src="~/image/map.jpg" usemap="#image-map" class="map" />
<map name="image-map" class="map">
<area target="" alt="" title="" href="" id="2" coords="1008,370,33" shape="circle">
<area target="" alt="" title="" href="" coords="962,420,23" shape="circle">
<area target="" alt="" title="" href="" coords="932,461,18" shape="circle">
<area target="" alt="" title="" href="" coords="888,464,867,485,907,541,929,501" shape="poly">
<area target="" alt="" title="" href="" coords="851,507,836,532,876,566,907,541" shape="poly">
</map>
<label id="mname"></label>
<label id="city"></label>
<label id="mid"></label>
<label id="cordsid"></label>
</form>
脚本
<script>
$(".map area").click(function () {
$.ajax({
url:'@Url.Action("Member_Detail")',
data: { 'cords': this.id },
type: "post",
cache: false,
dataType: "JSONP",
success: function (resdata) {
alert("success", resdata);
},
error: function (result, status, err) {
console.log("error", result.responseText);
console.log("error", status.responseText);
console.log("error", err.Message);
}
});
});
</script>
C#
public JsonResult Member_Detail(int cords)
{
string constr = ConfigurationManager.ConnectionStrings["Test"].ConnectionString;
MemberDetail m_Detail = new MemberDetail();
using (SqlConnection con=new SqlConnection(constr))
{
SqlCommand cmd = new SqlCommand("select * from Employee where EmployeeID='" + cords+"'", con);
cmd.CommandType = System.Data.CommandType.Text;
con.Open();
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
for (int i = 0; i < dt.Rows.Count; i++)
{
m_Detail.EmployeeID = Convert.ToInt32(dt.Rows[i]["EmployeeID"]);
m_Detail.Name = dt.Rows[i]["Name"].ToString();
m_Detail.Position = dt.Rows[i]["Position"].ToString();
m_Detail.Address = dt.Rows[i]["Address"].ToString();
m_Detail.Salary = dt.Rows[i]["Salary"].ToString();
m_Detail.Office = dt.Rows[i]["Office"].ToString();
}
}
return Json(m_Detail, JsonRequestBehavior.AllowGet);
}
【问题讨论】:
-
使用引导程序中的模态 getbootstrap.com/docs/4.1/components/modal
-
jquery代码如何写,在哪里写。
-
您首先需要 html 代码,然后在您的 ajax 成功中使用 bootstrap 中的 jquery 代码。您还必须在项目中链接 bootstrap(.js and.css)
-
以及如何给列名
-
jsfiddle.net/cristiannn/pb2wtaus/9 这是一个例子(它应该看起来像这样jsfiddle.net/cristiannn/pb2wtaus/11)