Solved

jquery mobile: event order, mobile init

Posted on 2013-02-07
1
513 Views
Last Modified: 2013-06-03
Here is what I am trying to do:

I am using JQ Mobile...latest.

1) Before I even get to any pages I want to go get userInfo from a passed in query string value
2) Hit the ajax call and set the global variables
3) Load the first page.

I can't seem to get the order straight....thanks in advance for the help.


//----------------------------------------------------/
//mobile init
//----------------------------------------------------/
$(document).bind("mobileinit", function () {
    //current date
    curDate = new Date();

    //log in user
    var curToken = GetUTokenParam('_uToken');   //// this is a QS variable
    params = "{'UserToken':'" + curToken + "'}";
    var u = GetService("45") + "ReturnUserGUIDByToken";
    $.ajax({
        type: 'POST',
        url: u,
        dataType: 'json',
        contentType: 'application/json; charset=utf-8',
        data: params,
        error: function (xhr, ajaxOptions, thrownError) {
            alert("Error[45s user token]" + u + " " + params);
            return false;
        },
        success: function (response) {
            if (response) {
                var data = response.d;
                curUser = {};
                curUser.UserGUID = data['EGUID'];
                curUser.UserLanguage = data['EntityLanguageID'];
                curUser.UserPeriod = data['EntityPeriodID'];
                curUser.UserName = data['EntityUserName'];
                curUser.UserFName = data['EFname'];
                curUser.UserLName = data['ELname'];
                curUser.UserEmail = data['EntityEmail'];
                curUser.IsLoggedIn = data['IsLoggedIn'];
            }


        }
    });
});


$('#main').live('pageinit', function () {
    alert(curUser.UserGUID);

});





here is my script order

JS
THIS FILE
MOBILE JS

Open in new window

0
Comment
Question by:skillilea
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38866027
ALL CSS
JS WHICH NOT USE jQuery
jQuery plugin
THIS FILE
JS using only jQuery but NOT jQuery Mobile Plugin (so forget mobileinit here and before!!!)
jQuery Mobile plugin
JS using jQuery Mobile

It appear your problem come from your Ajax call, you probably load jQuery Mobile before the success of your ajax call

S you can decide to include the others scripts, include which depend from your ajax call result inside your success callback :

        success: function (response) {
            if (response) {
                var data = response.d;
                curUser = {};
                curUser.UserGUID = data['EGUID'];
                curUser.UserLanguage = data['EntityLanguageID'];
                curUser.UserPeriod = data['EntityPeriodID'];
                curUser.UserName = data['EntityUserName'];
                curUser.UserFName = data['EFname'];
                curUser.UserLName = data['ELname'];
                curUser.UserEmail = data['EntityEmail'];
                curUser.IsLoggedIn = data['IsLoggedIn'];
$.getScript("js/jquery.mobile-1.2.0.js");
            }

Open in new window


If it don't work, you may need to load synchronously jQuery mobile plugin and after (success) load JS depending jQuery mobile plugin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now