简体   繁体   中英

Worklight 6.2 : Unable to add multiple js files in windows phone 8 environment

I created a multipage app using Worklight for Android,iOS & Windows Phone 8 platforms. In that app, I have to include multiple js files in some pages, which is creating issues in the Windows phone 8 environment.

Issue : If I include multiple js files, only first js file is loading in Windows phone 8 environment.

I created a sample application using Worklight multi-page app to demonstrate the issue.

In the Page1.html, I included 2 js files.

<script>
    $.getScript(path + "js/Page1.js");
    $.getScript(path + "js/Sample.js");
</script>

<p>
    Currently <b>Page1.html</b> page is loaded.
</p>

<input type="button" class="appButton" value="Show Alert" onclick="alertHello();" />
<input type="button" class="appButton" value="SimpleDialog from Page1" onclick="currentPage.buttonClick();" />
<input type="button" class="appButton" value="Insert Fragment" onclick="currentPage.insertFragment();" />

<div id="FragmentsDiv"></div>

<input type="button" class="appButton" value="BACK" onclick="currentPage.back();" />

Code in sample.js file

$(document).ready(function(){
    alert("sample.js loaded");
});

function alertHello()
{
    alert("hello");
}

When i tried to run the app in Windows phone 8 environment, Only the Page1.js is loading.

STEPS TO REPRODUCE ERROR

  1. Click "Load Page1.html"

  2. Click "Show Alert"

I am not getting the alert "hello" when I tried in windows phone 8 emulator/device.

Any help in solving the issue will be much appreciated.

You need to wait for the first script to be done to load the second script. getScript takes a second parameter you can pass a function, or you can use promises like and chain with a done() function

<script>
  $.getScript(path + "js/Page1.js").done(function(){
    $.getScript(path + "js/sample.js");
  });
</script>

I tried my self and it works 在此处输入图片说明

also notice that in your question in your code use use Sample.js with upper case "S" and in your comments you mentioned sample.js with lower case "s". I use sample.js in both file name and code.

Testing your sample project in windows Phone 8 emulator (via Visual Studio 12), after clicking the Page 1 button I got an alert saying "sample.js loaded". I then clicked on the Show Alert button and got an alert saying "hello".

Cannot reproduce...
Your sample as-is is working just fine in Worklight Studio 6.2.0.00-20140818-1919 (same version and build as yours).

Maybe you should edit your question and provide the full steps you have taken in order to reproduce this; maybe you are missing a step.

What I've done:

  1. Imported the project
  2. Right-clicked on the Windows Phone 8 folder > Run As > Visual Studio project
  3. VS opens > click on the "play" button
  4. WP8 emulator opens > did the above

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM