as practicing Ajax, I wrote a Ajax call that sends to a local Handler.ashx a Json with a username and password, and returns true if they are equal to "jhon" "123456", else false. I debugged the code, and I saw that the Handler.ashx receives the call, does the validation, and write to response, but the Ajax call not success.

this the Ajax call:

            url: '/Handler.ashx',
            dataType: 'json',
            data: {
                name: document.getElementById("username").value,
                password: document.getElementById("password").value
            success: function (json) {

and this is the server side:

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {

    public void ProcessRequest(HttpContext context)
        var name = context.Request["name"];
        var password = context.Request["password"];

        string response = IsValid(name, password) ? "true" : "false";
        context.Response.ContentType = "appliaction/text";
        context.Response.Write("{isvalid:'" + response + "'}");

    private bool IsValid(string name, string password)
        return (name == "jhon" && password == "123456");

    public bool IsReusable
            return false;



Related posts

Recent Viewed