日期:2014-05-17  浏览次数:20376 次

jquery执行后台asp.net方法的问题
各位好:
我现在有一个比较急的问题,详细内容如下:
我用jQuery的ajax方法来调用aspx文件中的方法时,在本机vs.net调试中运行很正常,但布置到IIS后就不执行,前台后台代码如下:
JScript code

$.ajax({
                    type: "POST",
                    url: "MessageMethods.aspx/AddMessageToDatabaseServer",
                    contentType: "application/json; charset=utf-8",                    
                    data: "{pw:'" + Math.random() + "',messageContent:'" + messageContent + "',mobiles:'" + allMobiles + "'}",
                    dataType: 'json',
                    success: function (result) {
                        //closeWaitingDialog("showWaiting"); //关闭等待提示框                                               
                        showCustomDialog("showResult", result.d); //显示操作结果对话框
                    }
                });



后台aspx页面的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
namespace DoorControlMain.Administration
{
  public partial class MessageMethods : System.Web.UI.Page
  {
protected void Page_Load(object sender, EventArgs e)
  {

  }

  /// <summary>
  /// 添加短信信息到后台数据库(这些短信用于后台Windows Service调用并发送)
  /// <param name="messageContent">要发送的短信内容</param>
  /// <param name="mobiles">要发送的手机号码(可以发送多个号码)</param>
  /// </summary>
  /// <returns></returns>
  [WebMethod]
  public static bool AddMessageToDatabaseServer(string messageContent, string mobiles)
  {
  try
  {
  //messageId为0表示新增一个短信,不过应该也不会修改短信的操作
  string[] mobilesArray = mobiles.Split(new char[] { ',', ';', ' ' });
  IRepository<SendingMessage> rep = new SendingMessageRepository();
  foreach (string mobile in mobilesArray)
  {
  rep.Add(new SendingMessage
  {
  MessageContent = messageContent,
  Status = false,
  MobileNumber = mobile,
  SentDate = DateTime.Now
  });
  }
  rep.UnitOfWork.Commit();
  rep.UnitOfWork.Dispose();
  }
  catch
  {
  return false;
  }

  return true;
  }
}
}
麻烦各位兄弟帮我分析下前后台这些代码有什么问题,谢谢了!

------解决方案--------------------
不执行那肯定是报错了,用Firebug或者HttpWatch看看报啥错。
------解决方案--------------------
前后台参数个数、名称要匹配
data: "{pw:'" + Math.random() + "',messageContent:'" + messageContent + "',mobiles:'" + allMobiles + "'}",

AddMessageToDatabaseServer(string messageContent, string mobiles)
------解决方案--------------------
貌似你的后台少了个using System.Web.Script;