Solved

jquery mobile: event order, mobile init

Posted on 2013-02-07
1
512 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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Recently, we decided that in order to stay competitive in today's IT world, we were going to have to develop and deploy a mobile app for our users and do it quickly. We felt that we were already behind the curve. Users of technology today are mov…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

772 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

15 Experts available now in Live!

Get 1:1 Help Now