0

I use .ajax to call a webservice mehod that sends an email to entered email.

I want to to show an ajax modal popup extender containg an image saying 'sendig...'

i used .ajax to call my webservice like:

var SendingModal = $find('SendMPE');
    var Resend = -1;
    $.ajax({
             async: false,
             type: "POST",
             url: "FinKaynWebService.asmx/SendEmail",
             data: "{'Email': '" + Email + "'}",
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             beforeSend: function() {
                 $("#SendMPE").show();
             },
             success: function(response) {
                 Resend = response.d;
                 SendingModal.hide();
              },
              failure: function(msg) {
                 alert('Sending Email failed,try later');
              }
    });

the problem is that my SendMPE is not showing.

<div id="SendingDiv" style="display:none;background-color:Yellow;color:Blue;">
     <img id="LoadingImage" alt="Still sending"  src="./Images/Sending.gif" />
    <span style="margin-left:10px;">Sending...</span>
    <asp:Button ID="CloseButton" runat="server" style="display:none;" />
</div>
<asp:ModalPopupExtender ID="SendMPE" X="200" Y="200" runat="server" 
                    TargetControlID="SendHiddenButton" PopupControlID="SendingDiv" 
           CancelControlID="CloseButton"></asp:ModalPopupExtender>

is this this problem caused by the image or what?

Who has an idea or has already done somthin like that:loading image in a popoup.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939

3 Answers3

0

Maybe you should remove 'style="display:none;' from SendingDiv. ModalPopupExtender will hide this div on startup.

Marek Kwiendacz
  • 9,524
  • 14
  • 48
  • 72
0

First of all you should use

data: '{"Email": "' + Email + '"}'

or better

data: JSON.stringify({Email: Email})

instead of

data: "{'Email': '" + Email + "'}"

see this answer for details.

One more remark. The event beforeSend(jqXHR, settings) should be use to modify jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object before it is sent (see jQuery.ajax documantation). In your case you can just place $("#SendMPE").show(); before the $.ajax call.

Moreover probably you want use $("#SendingDiv").show();?

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • the webservice method is executing when i debug.$("#SendMPE").show() the problem is just that the div is not showing.there is another popup that shows after the email is sent but not this one. –  Mar 01 '11 at 22:04
  • @user594166: Sorry, then you debug another code as you posted here. The result should be an error `{"Message":"Unrecognized escape sequence. (19): {\u0027Email\u0027: \u0027\Your.email@domain.com"\u0027}","StackTrace":" at System.Web.Script.Serialization.JavaScriptObjectDeserializer...`. But because you use not existing `failure: function(msg)` instead of `error(jqXHR, textStatus, errorThrown)` you will never see any errors. I seenn in your other question you used `JSON.stringify` so you know this. Probably your do debug not the code which you posted. – Oleg Mar 01 '11 at 22:15
  • @user594166: Do you tried with `$("#SendingDiv").show();` before `$.ajax` instead of `$("#SendMPE").show()` inside of `beforeSend`. Alternative you can use `SendingModal = $("#SendingDiv"); SendingModal.show();`? – Oleg Mar 01 '11 at 22:18
  • i have removed beforesend.No @Oleg,to show a modal popup extender we use var SendingModal = $find('SendMPE'); $("#SendingModal").show(); I call now $("#SendingModal").show() before .ajax but nothing happens. –  Mar 01 '11 at 22:25
  • @user594166: Probably you have "div#SendingDiv" concealed with another elements. Try to add style="z-index:1100;" to the "div#SendingDiv". – Oleg Mar 01 '11 at 22:31
  • i have added the z-index:1100 .and i removed the modal popup.
    $("#SendMeButton").live("click", function(event) { event.preventDefault(); $("#SendingDiv").show(); .it deosn' work but when i call it from link it works.
    –  Mar 01 '11 at 22:44
  • @user594166: I suppose you have some problem in the part which you not posted in the text of your question. I personally use [jQuery BlockUI Plugin](http://jquery.malsup.com/block/) to show/hide for the purpose. It work very good. Sometime I use more simple div (see [here](http://stackoverflow.com/questions/4473690/jqgrid-need-to-change-progress-message-loading/4474749#4474749)) – Oleg Mar 01 '11 at 22:51
  • i found out that it show but it hides quickly before it loads.Howa can i wait until it loads(shows) then call .ajax –  Mar 01 '11 at 23:06
  • @user594166: You can include `alert("bla bla");` in the corresponding place before `$.ajax`. You can also include `alert` at the beginning of `success` handler. – Oleg Mar 01 '11 at 23:12
  • Here is the fix for guys who meet the same problem:wait untill the sending divs show before calling .ajax $("#SendingDiv").show('200', function() { $.ajax({...}); }); –  Mar 01 '11 at 23:17
0

This may not be exactly what you have in mind, but I typically follow the following general pattern. I have the request as a generic function (unimportant for your purpose), but have methods of callbacks handle process/error with the handler itself being instantiated being responsible for showing the modal.

AJAX Call:

var data = $.toJSON("{'obj:' + obj + "}");
var URI = "/FinKaynWebService.asmx/SendEmail";
var MSG = $("#modalDiv")
ajaxRequest(data, URI, new genericHandler(msg));

AJAX function:

function ajaxRequest(requestData, serviceURI, handler) {

  $.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: serviceURI,
    data: requestData,
    dataType: "json",
    cache: false,
    success: function(result) {
      callbackFunction.Process(result);
    },
    error: function(msg) {
      callbackFunction.OnError(msg.responseText)
    }
  });

}

Handler:

function genericHandler(msg) {
  $.blockUI(msg)
  this.Process = function(d) { alert("Data updated sucessfully.") };
  this.OnError = function(d) { alert(d.toString()) };
}
iivel
  • 2,576
  • 22
  • 19
  • the problem is not that the call deosn't happens.The call happens,and the email is sent.the problem is that my sendingdiv doesn't show when i call .show() in send button click event.When i call it in another link click event,my sending div shows. –  Mar 01 '11 at 22:51