在ASP.NET中使用jquery绑定转发器时出现问题 [英] Problem while binding repeater using jquery in ASP.NET
本文介绍了在ASP.NET中使用jquery绑定转发器时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的剧本
My Script
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
var $= jQuery.noConflict();
function FillNotifications() {
$.ajax({
type: "POST",
url: "home.aspx/GetNotifications",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
var table = $("#dvNotification table").eq(0).clone(true);
var Notifications = response.d;
$("#dvNotification table").eq(0).remove();
$(Notifications).each(function () {
$(".shownotificationsid", table).html(this.shownotificationsid);
$(".notificationid", table).html(this.notificationid);
$(".subject", table).html(this.subject);
$(".message", table).html(this.message);
$("#dvNotification").append(table).append("<br />");
table = $("#dvNotification table").eq(0).clone(true);
});
}
function ShwoNotification() {
FillNotifications();
$("#divnotify").fadeIn("slow");
}
$(function () {
setInterval('ShwoNotification()', 5000);
});
$(document).ready(function () {
$("#closenotify").click(function () {
$("#divnotify").fadeOut("slow");
});
});
</script>
中继器设计代码
Repeater design Code
<div id="dvNotification">
<asp:Repeater ID="repnotification" runat="server">
<ItemTemplate>
<tr style="removed: pointer;" >
<td style="width: 50%;">
<%# Eval("subject")%>
</td>
<td style="width: 30%;"><%#Eval("message")%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</div>
我的代码落后(C#)
My Code behind(C#)
public class Notifications
{
public string shownotificationsid { get; set; }
public string notificationid { get; set; }
public string subject { get; set; }
public string message { get; set; }
}
[WebMethod]
public static List<Notifications> GetNotifications()
{
string constr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM ShowNotifications where showstatus=1 and toid=" + HttpContext.Current.Session["EmployeeId"] + ""))
{
cmd.Connection = con;
List<Notifications> notifications = new List<Notifications>();
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
notifications.Add(new Notifications
{
shownotificationsid = sdr["shownotificationsid"].ToString(),
notificationid = sdr["notificationid"].ToString(),
subject = sdr["subject"].ToString(),
message = sdr["message"].ToString(),
});
}
}
con.Close();
return notifications;
}
}
}
当我在
When I checked console on
$.ajax({
i我收到此错误
VM1552:1未捕获的SyntaxError:意外的输入结束(...)
FillNotifications @ home.aspx:303
ShwoNotification @ home.aspx:334
(匿名函数)@ VM336:1
所以请帮忙我找出错误的地方.....
我尝试过的事情:
以上代码为我所尝试的内容提供了我在哪里遇到错误....
i am getting this error
VM1552:1 Uncaught SyntaxError: Unexpected end of input(…)
FillNotifications @ home.aspx:303
ShwoNotification @ home.aspx:334
(anonymous function) @ VM336:1
So please help me to find out where i did mistake.....
What I have tried:
Above Code Provided for what i tried and where did i got error....
推荐答案
= jQuery.noConflict();
function FillNotifications(){
= jQuery.noConflict(); function FillNotifications() {
.ajax({
type: POST,
url: home.aspx / GetNotifications,
data:' {}',
contentType: application / JSON; charset = utf-8,
dataType: json,
成功:OnSuccess,
失败: function (响应){
alert(response.d);
},
错误: function (响应){
alert(response.d);
}
});
}
function OnSuccess(响应){
var 表=
.ajax({ type: "POST", url: "home.aspx/GetNotifications", data: '{}', contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function (response) { alert(response.d); }, error: function (response) { alert(response.d); } }); } function OnSuccess(response) { var table =
( #dvNotification table)。eq( 0 )。clone( true );
var Notifications = response.d;
("#dvNotification table").eq(0).clone(true); var Notifications = response.d;
这篇关于在ASP.NET中使用jquery绑定转发器时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文