Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

IBM Worklight 6.0.0.1 - JavaScript not executing in a jQuery Mobile multipage app

I am using IBM Worklight Studio version_6.0.0.20130926-2018.

In my app I am using the jQuery Mobile framework.
My problem is that when I try to load a data-role="page" using $.mobile.changePage, the page is not refreshed by itself. When I refresh this page, the JavaScript code is not working.

Instead, I get the following errors:

 ReferenceError: WLJQ is not defined profile.html:11
 TypeError: $ is undefined jquery.mobile-1.3.2.js:28
 ReferenceError: $ is not defined profile.js:3
 ReferenceError: WL is not defined

The $.mobile.changePage code:

//redirect to profile
    function redirectToProfile(profileId){
        if(profileId == null || profileId == ""){
            $("#failMessage").fadeIn();
        }
        else{
            var dataurl = '?profileID='+profileId;
            $("#failMessage").fadeOut(200, function(){$("#loginSuccess").fadeIn(function(){$.mobile.changePage('pages/profile.html'+dataurl, {reloadPage : true,transition: "slide"});});});

        }
    }
}); 

How to solve this in Worklight?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If I understand correctly you created another HTML page that you navigated to. It is not the right way to do navigation when using Worklight. Worklight is a single-page application!, so you need to use a div element that switches the content instead of navigating between pages. More information regarding this can be found here: http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v610/03_02_Building_a_multi_page_application.pdf


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...