ajaxTest.aspx 中 <input type="text" id="txtCategoryName" runat="server" />ajaxTest.aspx.cs中
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxTest));
}
/// <summary>
/// 判断用户名是否存在
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public bool JugeCategoryName(string Name)
{
//////
}AddCategory.js中
$(document).ready(function(){ //分类名验证
$("#txtCategoryName").bind("blur",function(){
var $parent=$(this).parent();
var str= $.trim($(this).val());
alert(str);
$parent.find(".formtips").remove();
var CategoryJuge=ajaxTest.JugeCategoryName(str);
});
});
在线等,求求好心人帮忙
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxTest));
}
/// <summary>
/// 判断用户名是否存在
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public bool JugeCategoryName(string Name)
{
//////
}AddCategory.js中
$(document).ready(function(){ //分类名验证
$("#txtCategoryName").bind("blur",function(){
var $parent=$(this).parent();
var str= $.trim($(this).val());
alert(str);
$parent.find(".formtips").remove();
var CategoryJuge=ajaxTest.JugeCategoryName(str);
});
});
在线等,求求好心人帮忙
如不能 就是你 js写错了在你的web.config 中 要配置 ajaxpro
JugeCategoryName,前面一句还能执行,就是掠过了JugeCategoryName()这个方法
JugeCategoryName()这个方法 执行不到吗
如果是 那就是你调用后台方法时出错了
ajaxTest.JugeCategoryName(str); 出错了 我在用的时候都是 命名空间.ajaxTest.JugeCategoryName(参数).value 这样用的
就是后台没调用到
我没声明命名空间,那我该怎么引用.ajaxTest.JugeCategoryName(参数).value
<head runat="server">
<script src="JS/jquery-1.3.2.js" type="text/javascript"></script>
<script src="JS/AddCategory.js" type="text/javascript"></script>
<title>无标题页</title>
</head>
<body>
<div class="right_title">
<img alt="" src="Images/fy_003.gif" width="4" height="29" />
<h2>当前位置:后台管理系统 >分类管理 ><a>分类添加</a> </h2>
<span><img alt="" src="Images/fy_002.gif" width="4" height="29" /></span>
<div class="null"></div>
</div>
<div class="right_content">
<form runat="server" id="form1">
<table border="0" cellpadding="0" cellspacing="0" class="right_content_whole">
<tr>
<td class="table_name">分类名称:</td>
<td class="table_content">
<input type="text" id="txtCategoryName" runat="server" />
</td>
</tr>
<tr>
<td class="table_name"></td>
<td class="table_content">
<div class="content_submit">
<asp:ImageButton ID="ibtnAdd" runat="server" Width="108" Height="27"
ImageUrl="Images/fy_19.jpg" OnClick="ibtnAdd_Click" OnClientClick="return CheckForm();" />
</div>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class ajaxTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ }
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajaxTest));
}
/// <summary>
/// 判断用户名是否存在
/// </summary>
/// <param name="Name"></param>
/// <returns></returns>
[AjaxPro.AjaxMethod]
public bool JugeCategoryName(string Name)
{
Core.SP<QueryParam.Category, Model.Category> usp = new Core.SP<QueryParam.Category, Model.Category>();
usp.QueryParam.CategoryName = txtCategoryName.Value.Trim();//用户名
Core.Result<Model.Category> uspResult = usp.Run("IsExists");
if (uspResult.ErrorCode == 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 添加分类
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ibtnAdd_Click(object sender, ImageClickEventArgs e)
{ if (!string.IsNullOrEmpty(txtCategoryName.Value.Trim()))
{
Core.SP<QueryParam.Category, Model.Category> usp = new Core.SP<QueryParam.Category, Model.Category>();
usp.QueryParam.CategoryName = txtCategoryName.Value.Trim();
usp.ShowColumns = "CategoryName";
Core.Result<Model.Category> uspResult = usp.Run("AddCategory");
if (uspResult.ErrorCode == 0)
{
CommonMethod.Alert("添加成功!");
}
else
{
CommonMethod.Alert(uspResult.ErrorMessage);
}
}
}
}
web.config 配置
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
</httpHandlers>