Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

problem in pass data with $.ajax and get 500 Internal Server Error

$
0
0

i have a problem for pass data in $.ajax,

i want pass data in $.ajax but when run project i get null data in c# code , i created breack point in code behind and get this error: Object reference not set to an instance of an object and in firebug i get this error: 500 Internal Server Error

 my url params in $.ajax was passed but data don't pass :( where wrong my code? please help me

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();
    }



Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>