I'm learning aJax and have a simple aJax call to httphandler class. I submit a simple form and want to display a success/fail message.

I send a couple of parameters to my handler via "GET". Then I do comparison of given numbers with expected once. In my case they are equal, but condition in handler is not evaluated to true.

It is probably a silly question, but I was just wandering what I'm missing.

This is my html:

    <label>Enter your Name</label>
    <input type="text" name="uname" class="uname"/> <br/>
    <label>Enter your Password</label>
    <input type="password" name="password" class="passwd"/> <br/>
    <input type="submit" id="submit"/>
<div id="message"></div>

This is aJax call:

$(function () {
    $('#submit').click(function () {
        var name = $('.uname').val();
        var pwd = $('.passwd').val();
        var data = 'uname=' + name + '&password= ' + pwd;
            type: "GET",
            url: "../pages/handler.ashx",
            data: data,
            success: function (html) {
        return false;

This is a handler:

public void ProcessRequest(HttpContext context)
    string uname = context.Request["uname"].ToString();
    string pwd = context.Request["password"].ToString();
    //context.Response.ContentType = "text/plain";
    if (uname == "test" && pwd == "12345")
        context.Response.Write("Welcome " + uname);
        context.Response.Write("Sorry you are not authorized");

I submit "test" as a user name and "12345" as a password and expect condition to be true but I get "Sorry you are not authorized" response.

Why is it not working?

Related posts

Recent Viewed