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?

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

in a.js

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

use yourGlobal in b.js

if(yourGlobal) {
   function callGlobalFunction() {
        alert(yourGlobal)
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.