Reputation: 1885
I load a jQueryMobile dialog using this code:
<a data-rel="dialog" href="/path/to/dialog?arg1=val1" data-theme="b" id="deleteButton" class="ui-btn-right home" data-direction="reverse" data-transition="slidedown">Delete</a>
My dialog has two buttons:
<a data-role="button" href="/path/to/page/that/showed/dialog" id="deleteAddressButton" data-rel="back">Delete</a>
<a data-role="button" data-theme="a" href="/path/to/page/that/showed/dialog" data-rel="back">Cancel</a>
When I click the buttons the dialog closes and returns to the page that opened the dialog. However, the page that opened the dialogs is being reloaded via ajax, which seems unnecessary and is breaking things. Does anyone have any idea why this happening? Shouldn't the dialog just be able to close without reloading the calling page?
Note: The calling page is only reloaded if I originally go to a different page, for example:
Home page -> Page that calls dialog -> Dialog
The problem happens when I go to home page first, then page that calls dialog. If I do a full page reload on Page that calls dialog and then open and close the dialog, the page that calls dialog is not reloaded via ajax.
Edit: This is happening on jQuery Mobile's documentation site also. To see this:
Upvotes: 4
Views: 10148
Reputation: 31
It seems to be a bug and I've opened an issue for jquery-mobile at github along with a patch.
Upvotes: 3
Reputation: 36
Edit
An easy solution is to use a non-ajax link for the page that calls the dialog
<a href="url/to/page-that-calls-dialog" data-ajax="false">...</a>
That works at the cost of losing the DOM cache and having to reload the entire page.
It looks like we must wait until jQuery gives the correct behavior to the dialog widget.
The reason
That happens because jQuery mobile keeps only three pages in the DOM:
The first one lives until you do a non-ajax navigation (e.g. refresh the browser or type the URL and then press enter) if so, the new one becomes the first page.
The second one only apears when you are changing to another page, and lives the same timespan than the first.
The third one always holds the new page you are navigating to, and (here is the 'troll-magic') it's replaced each time you navigate using ajax.
In this order of ideas:
When you enter to your "Home page" the first page is set to your "Home page".
When you go to your "Page that calls dialog" the sencond page is created an the third one is set to "Page that calls dialog".
When you call your dialog, this replaces the former third page, so your "Page that calls dialog" gets removed from DOM.
Upvotes: 2
Reputation: 4019
Edit
This does the trick, and make sure you're using $('#yourDialog').dialog('close')
$.mobile.page.prototype.options.domCache = true;
I can confirm that even though only the pageshow is firing when closing the dialog as expected, jQM still does an AJAX request for the page. It'd be nice if this wasn't the only way, but so far it looks as if that's so.
Upvotes: 1
Reputation: 1885
jQuery Mobile's website does the same thing so it must be the default behavior.
Upvotes: 0
Reputation: 3827
Are you doing anything in the "pageShow" callback? Because that's probably what's causing this. The "pageShow" event is going to get fired again once you hide the dialog.
If you don't want it to show, you are going to either need to restructure your code to handle this accordingly, or use the "pageLoad" instead of page show. Here is a link to the JQM docs describing this behavior: http://jquerymobile.com/test/docs/api/events.html
Upvotes: 1