?
Solved

jquery mobile: event order, mobile init

Posted on 2013-02-07
1
Medium Priority
?
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

777 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