0

I have a.js and qunits are written in b.js,input data will be present in a.js,so inorder to use that input data of a.js in b.js,how can i do.i know that both js files can be included in html page.but b.js contains qunits for javascript methods (just like junits) these will be ran from build.xml so i cannot have a html Hence i cannot use html.

I tried invoking methods of a.js since both files are in same directory but didnt worked out.

is there any other way to use data of a.js in b.js?

muneebShabbir
  • 2,500
  • 4
  • 29
  • 46
javalearner
  • 347
  • 2
  • 7
  • 21

3 Answers3

1

when you are in b.js write

$(document).ready({
$.ajax({
url: "",
context: document.body
}).done(function() {

});
});

and in this do ajax call to bring the contents of a.js and use that content on this page anywhere you need.

Naveed Yousaf
  • 133
  • 2
  • 13
1

What you need is to include a Javascript file into another, have a look at this answer

To be briefly, there are two main methods to make it(Copy from the answer I mentioned) :

  • You can load it with an Ajax call and then use eval.
  • Add a script tag with the script URL in the HTML.
Community
  • 1
  • 1
WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138
0

in a.js

yourGlobal = {}
yourGlobal.data = {a: 'good', b: 'c'}

use yourGlobal in b.js

if(yourGlobal) {
   function callGlobalFunction() {
        alert(yourGlobal)
   }
}
jingyinggong
  • 636
  • 5
  • 9