-4

Is there any way to know when a web server response is sent to the client, in a traditional postback, so that I can execute a jQuery function?

For example, to put a div with a message or a simple alert saying "Succeed" without using the

Page.RegisterStartUpScript("<script type="text/javasctip">alert('Succeed')</script>);

nor

var request = $.ajax({
   url: "page/someWebMethod",
   type: "POST",
   data: {id : menuId},
   dataType: "html"
 });

 request.done(function(msg) {
    $('DivOk').show();
 });
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
anmarti
  • 5,045
  • 10
  • 55
  • 96

3 Answers3

1

It's hard to answer without a specific application, however, remaining within jQuery methods, you could use the ansync: false option for jQuery's ajax method and make a synchronous as demonstrated on the answer here: How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

Community
  • 1
  • 1
cgspicer
  • 49
  • 3
0

You can check the HTTP method used (assuming you've done a POST for example), then do something, for example in your ASPX:

<script type="text/javascript">

    var has_posted = <%= GetPosted() %>;

    if (has_posted) callSomething();

</script>

In the code behind:

protected string GetPosted()
{
    return (Request.HttpMethod == "POST").ToString().ToLower();
}

I usually do this using <form> however so can pass in extra checks using hidden <input> fields, but you get the idea.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
0

Edit: (a none traditional way) :)

shouldn't jQuery.ajax's success give you what you want?

$.ajax({
  url: 'ajax/test.html',
  success: function(data) {
    $('.result').html(data);
    alert('Load was performed.');
  }
});
woodykiddy
  • 6,074
  • 16
  • 59
  • 100