Solved

jquery mobile: event order, mobile init

Posted on 2013-02-07
1
517 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

821 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