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: