日期:2014-05-16  浏览次数:21085 次

引用AJAX.dll后无反应,也没法调试
前台
  <script type="text/jscript">
        function data() {
            alert("sss");
             _Default.DataConn();
        }
    </script>


后台
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.Utility.RegisterTypeForAjax(typeof(_Default));
      
    }

   [Ajax.AjaxMethod]
   public void DataConn()
    {
      
        SqlConnection sqlCon = new SqlConnection();
        sqlCon.ConnectionString = "Data Source=WQ-20130418DUMH;Initial Catalog=Test;User Id=sa;Password=123;";
        string sql = string.Format("insert into Test(Title,UserName,Email,Pic,Date,Content) values('{0}','{1}','{2}','{3}',getdate(),'{4}')",Request["txtTitle"],Request["txtName"],Request["txtEmail"],Request["updata"],Request["txtContent"]);
        sqlCon.Open();
        try
        {
            SqlCommand command = new SqlCommand(sql, sqlCon);
            if (command.ExecuteNonQuery() > 0)
            {
                Response.Write("<script>alert('保存成功')</script>");
            }
            else
            {
                Response.Write("<script>alert('保存失败')</script>");
            }
            
        }