erro与$ .ajax传递数据并获得500内部服务器错误

时间:2013-09-15 12:50:47

标签: c# jquery asp.net ajax

我在$ .ajax中传递数据有问题, 我想在$ .ajax中传递数据但是当运行项目时我在c#代码中得到空数据并得到: 检查元素中出现500内部服务器错误, $ .ajax中的我的网址已通过,但数据未通过:( 哪里错了我的代码? 请帮帮我

var value= {
    oldpassword: $('#oldpassword').val(),
    newpassword: $('#newpassword').val()
}

$.ajaxService({
    url: 'http://localhost:1549/Store/Pages/services.aspx?ServiceName=hello-world',
    data:JSON.stringify(value),
    onStartService: function () { 
        $(options.target).addClass('loading'); 
    },
    onEndService: function () { 
        $(options.target).removeClass('loading'); 
    },
    onResponse: function (response) {
        if (response.result == '1') {
            $.pushMessage({ 
                message: 'success', 
                messageClass: 'success-message', 
                delay: 3000
            });
        else {
            $.pushMessage({ 
                message: 'error', 
                messageClass: 'success-message', 
                delay: 3000 
            });
        }
    }
});
}
NameValueCollection ResponseResultCollection = new NameValueCollection();

protected void Page_Load(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(2200);
    string serviceName = this.Request.QueryString["ServiceName"];
    if (!string.IsNullOrEmpty(serviceName))
    {
        switch (serviceName.ToLower().Trim())
        {
            case ("hello-world"):
                string oldpassword = Request["oldpassword"].ToString();// its null
                string newpassword = Request["newpassword"].ToString();//its null
                try
                {
                    System.Web.Security.MembershipUser usr = System.Web.Security.Membership.GetUser();
                    if (usr.ChangePassword(oldpassword, newpassword))
                        ResponseResultCollection["result"] = "1";
                    else
                        ResponseResultCollection["result"] = "0";
                }
                catch (Exception ex) { 
                    Response.Write("An exception occurred: " + Server.HtmlEncode(ex.Message) + ". Please re-enter your values and try again."); 
                }
                break;
            }
        }
        Response.Write(this.GenerateResponseResult());
        Response.End();
    }

    private string GenerateResponseResult()
    {
        string result = "";

        foreach (string key in this.ResponseResultCollection.AllKeys)
        {
            result += string.Format(",\"{0}\":\"{1}\"", key, this.ResponseResultCollection[key]);
        }

        if (!string.IsNullOrEmpty(result))
        {
            result = result.Substring(1);
            result = "{" + result + "}";
        }

        return result.ToString();
    }

0 个答案:

没有答案