Eric Hansen
Eric Hansen

Reputation: 313

jQuery Mobile : page not loading completely on initial visit

I looked through all the similar questions that showed up before typing this, but I can't find an answer for my issue.

I'm using jQuery Mobile (1.1) and jQuery (1.7.1) to develop a small portal. As such, I have it all on one page, and use data-role="page" to handle the process transitions.

The flow is currently like this:

  1. User visits main URL
  2. User clicks on an action ("do this" or "do that")
  3. When a user clicks on the action (both are just tags with a href to another file with data-role="button"), it takes them to that page just fine.

However, when first visiting the page (either by manually typing in the URL or clicking on the action button/link), the form is empty and clicking the submit button does nothing. After refreshing the page though everything works as it should.

So, say for example someone clicks on action link #1 ("make a payment"):

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<title>Credit Card Payments</title>
<style>
    .ui-dialog .ui-header a[data-icon=delete] { display: none; }
</style>
<script>
$(document).bind("mobileinit", function(){
});
</script>
</head>
<body>
    <div data-role="dialog" id="popup">
        <div data-role="header" data-theme="b" data-content-theme="b">
            <h1>Destination</h1>
        </div>
        <div data-role="content" data-theme="b" data-content-theme="b">
            Please choose what you would like to do:
            <a href="payment.php" data-role="button">Make A Payment</a>
            <a href="create.php" data-role="button">Add Credit Card To Account</a>
        </div>
    </div>
</body>
</html>

It takes them to "payment.php" and displays page id "step1", which is a simple log in form:

<div data-role="page" id="step1">
    <div data-role="header">
        <h2>Log In</h2>
    </div>
    <form id="step1frm">
        <div data-role="fieldcontain">
            <label for="mail">Blesta e-mail: </label>
            <input type="text" name="mail" id="mail" />
        </div>
        <div data-role="fieldcontain">
            <label for="pw">Blesta password: </label>
            <input type="password" name="pw" id="pw" />
        </div>
            <input type="button" id="step1frmsub" value="Log In" />
    </form>
</div>

The log in form page also has a lot of jQM stuff but after I commented all the code out it didn't change anything so that isn't the cause. I also verified the HTML via W3.org and it came back valid.

A better representation of what's going on can be found in the screen shots I took of Chrome's Inspector:

First Visit - after clicking "make a payment"

After Refreshing Page - after refreshing the login for "make a payment"

Edit - As a small follow up, I noticed "data-external-page="true"" is being set on the div page on load, and then on refresh it's not there anymore. From my understanding of what I've read this is done because it's coming from a dialog basically, but I'm not sure if there's a way to disable that from being set.

Answer - Well, the solution to this, after initially thinking it wasn't what I was looking for, was actually to add this to my links:

rel="external"

So that they look like this:

<a href="payment.php" data-role="button" rel="external">Make A Payment</a>

Upvotes: 1

Views: 1791

Answers (1)

Eric Hansen
Eric Hansen

Reputation: 313

Well, the solution to this, after initially thinking it wasn't what I was looking for, was actually to add this to my links:

rel="external"

So that they look like this:

<a href="payment.php" data-role="button" rel="external">Make A Payment</a>

Upvotes: 1

Related Questions