首页 新闻 会员 周边

帮忙找找ajax的错误

0
[已解决问题] 解决于 2012-05-06 10:42

哪位帮我看看我这个代码出什么问题了,被纠结一天了

这是前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="无刷新评论.aspx.cs" Inherits="传智播客.ajax.无刷新评论" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        #TextArea1 {
            height: 60px;
            width: 184px;
        }
    </style>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var comment = $("#TextArea1").html();
            $("#Button1").click(function () {
                $.post("noFreshComment.ashx", { "comment": comment }, function (data, status) {
                    if (status == "success") {
                        if (data == "插入成功") {
                            alert("评论成功");
                        }
                    }
                })
            });
        })
    </script>
</head>
<body>
    <form runat="server">
    <div>
        <textarea ></textarea>
        <br />
        <input type="button" value="评论" />
    </div>
    </form>
</body>
</html>


 

这是后台ashx代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using 传智播客.DAL.DataSetCommentTableAdapters;
using System.Windows.Forms;

namespace 传智播客.ajax
{
    /// <summary>
    /// 无刷新评论1 的摘要说明
    /// </summary>
    public class 无刷新评论1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string comment=context.Request["comment"];
            MessageBox.Show(comment);
            if (comment!= "")
            {
                T_CommentTableAdapter adapter = new T_CommentTableAdapter();
                adapter.InsertNewComment(comment);
                context.Response.Write("插入成功");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

 

为什么调试的时候发现comment=""呢?

微澜的主页 微澜 | 初学一级 | 园豆:-1
提问于:2012-05-06 10:08
< >
分享
最佳答案
0

看是否是这个原因:http://q.cnblogs.com/q/34266/

奖励园豆:5
artwl | 专家六级 |园豆:16736 | 2012-05-06 10:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册