3

In this scenario:

  • User enters some information into a textbox
  • User clicks a button
  • Server-side processing of the entered information takes place
  • Depending on the result of that server-side processing, either a new window is to be opened, or a message is to be displayed on the current page (and no popup)

I cannot come up with an approach other than to use async: false in the jQuery ajax call, which is strongly discouraged:

Setting this option to false (and thus making the call no longer asynchronous) is strongly discouraged, as it can cause the browser to become unresponsive.

I've tried:

  • having the call be async and in the callback handler, depending on what the server said, sometimes opening a new window - this gets blocked by popup blockers
  • another idea, which I've not even bothered with due to its unpleasantness, is to always open a window, and it is this new window that calls the server, and sometimes closes itself (somehow updating text in the parent on its way out)

What I've settled on is what I've described above: in the click handler, do a synchronous server call, and if the server says to do so, open a new window. Popup blockers are happy with this, because the window opening is done in the click handler. But...


Similar (but not duplicate, as I don't always want to open a new window) questions that have not provided a nice solution:

Community
  • 1
  • 1
AakashM
  • 62,551
  • 17
  • 151
  • 186
  • 1
    Do you really need to open a new window? Can't you just open an overlay box or similar? – Zeta Two Aug 24 '11 at 11:54
  • Same question as Zeta, and also, as the jQuery documentation says, doing sync server communication is strongly discouraged...if you don't get the server response immediately, your user will not be able to do anything else on your page. Basically, the browser hangs until the server response comes through or errors. – jyore Aug 24 '11 at 12:04
  • The constant constraint of specifications I'm afraid... I know this is bad, I seek a better way. – AakashM Aug 24 '11 at 12:18
  • +1 to Zeta's comment. Lightbox Me is a lightweight modal that is developer friendly (unlike most Lightbox plugins) http://buckwilson.me/lightboxme/ – Cory Gagliardi Sep 13 '11 at 18:36

2 Answers2

0

what you can do is ,

try to have a hidden field on your page which will be set by a value like true or false at server side , that you can check later on in jquery document .ready function

if the value is false just show a msg else popup a new window

as simple as that

Vijay Parmar
  • 795
  • 4
  • 13
  • Thanks for answering, but I don't want to post back the whole page, which is I think what you mean by setting a hidden field value server-side? – AakashM Sep 27 '11 at 11:16
  • if your are making Ajax call surely you will be getting a html/data,try to get extra value from server which will decide whether to to popup or not. – Vijay Parmar Oct 22 '12 at 08:28
0

I tried out my 'unpleasant' idea: to always open a new window, and have that new window make the server call, closing itself if the results of the server call dictated that it was not required.

But that was pretty horrible, so I stuck with the synchronous call.

So for me, the answer to this question is no, you can't avoid being synchronous in this situation.

AakashM
  • 62,551
  • 17
  • 151
  • 186