0

I'd like to know how can I invoke a function in an aspx handler(.ashx).

This is what I've tried:

public void ProcessRequest(HttpContext context) ...

context.Response.ClearContent();
context.Response.ContentType = "text/javascript";
context.Response.Write("<script>$('#showAlert').show();</script>"); 

but this does nothing, I'd like to know if is it possible and if it is how can I do it.

I can refer that the aler is written in a web user control.

//THIS IS USED TO CALL THE HANDLER

$("#saveChanges").click(function () {
        $("#gif").show();
        $.ajax({
            url: "../handlers/adminSaveResults.ashx?pinAntigo=" + $("#pin").val() + "&pinNovo=" + $("#pinNovo").val() + "&passAntiga=" + $("#old").val() + "&passNova=" + $("#newP").val() + "",
            type: "POST",
            data: {},
            async: true,
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function (data) {
                $("#gif").hide();
            },
            error: function (data) { /*alert("ERRO: " + data.status);*/ $("#gif").hide(); },
            timeout: 15000
        });
    }
  );

Regards

Incredible
  • 3,495
  • 8
  • 49
  • 77
Severiano
  • 1,083
  • 3
  • 25
  • 54

1 Answers1

0

If I understand correctly what you want, it should be something like this:

Server:

public void ProcessRequest(HttpContext context) ...    
context.Response.ClearContent();
context.Response.ContentType = "application/json";
context.Response.Write("{"ok": 1 }"); 

And here is the js:

$("#saveChanges").click(function () {
        $("#gif").show();
        $.ajax({
            url: "../handlers/adminSaveResults.ashx",
            type: "POST",
            data: {pinAntigo: $("#pin").val(),
                   pinNovo: $("#pinNovo").val(),
                   passAntiga: $("#old").val(),
                   passNova: $("#newP").val() } ,
            async: true,
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function (data) {
            if(data.ok){
                {
                    $('#showAlert').show();
                }     
                $("#gif").hide();
            },
            error: function (data) { /*alert("ERRO: " + data.status);*/ $("#gif").hide(); },
            timeout: 15000
        });
    }
  );
Rudy
  • 2,323
  • 1
  • 21
  • 23