[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

jquery mobile: event order, mobile init

Posted on 2013-02-07
1
Medium Priority
?
527 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

656 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