I'm working on a simple project where I included a simple js file to fetch out a data from api on click of a button. It was working when I had HTML file and js file in same folder and used by simply clicking on index.html . Now i am using expressjs for same and written all the HTML code in index.ejs file. For some reason, the js file has stopped working. I have tried changing the paths and carefully defining the path, also kept the file in same folder as of ejs file but it does not seem to work. Any suggestions would be helpful. The lines I have included in ejs file as are as follows. Here the js file is in the js folder of public folder of the project
<script src="jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>
I got this problem resolved by adding the following path to jQuery src
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"
instead of
"jquery-3.2.1.min.js"
Related
here the link to a project I am working on to learn express / ejs / API.
https://github.com/aspnet82/books
I would like to add a second JS file to manage clicks etc.. possibly using jQuery (also vanilla JS is ok... at the moment there is no jQuery installed).
// books.ejs
<script src="public/js/index.js" charset="utf-8"></script>
</body>
But when I add the tag and indicate the index.js as source into the books.ejs file the content of the webpages is not showing anymore, is like either the app.js or the index.js are loaded at time.
If index.js is empty the ejs file is loaded properly.
What is the best way to manage events on a node / express app? For example, if I click on a element. Is this a Js file into the public folder as it is static content? and how do I call this in the app.js file?
Thanks for any help
I am new to Nodejs and having trouble when trying to export my js code which exists in HTML files to more js files for less redundancy in code (same js code in two HTML files):
I exported the js code from both HTML files to js a file (js_code_file.js for example) and tried using <script src="js_code_file.js" type="text/javascript"></script> in the header of the HTML file in order to import the file, and it did not work.
Is it because of Nodejs? and if it is - is there a way to "require" these files somehow?
<script src="js_code_file.js" type="text/javascript"></script>
Looking at the src attribute, js_code_file.js has to be in the same path as the .html file referencing it; that is, it has to literally be in the same folder. So make sure that is the case, otherwise, update your question with any errors you might be receiving.
We have been using WaveMaker and wanted to know how we can go about importing an external javascript file using the platform ?
The external JS file should be imported into a folder in resources
The file path has to be given in login.html of the Web-App
The file path should be of the form "/projectname/foldername/filename.js/"
The functions in the external JS file can be accessed in the login page through its script and the function invoked here is from a sample js file.
The following works if using WaveMaker 6. This probably doesn't work with newer versions of WaveMaker.
Instead of having to add it to each project, try editing index.html in the webapproot directory and add you external js file:
<!-- Boot Wavemaker -->
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="/<path to javascript file>/sha512.js"></script>
Then, in order to have this work correctly in your development environment, add a context tag to server.xml just above the projects directory:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
<Context docBase="c:/<Path To Javascript Filet" path="<path to javascript file matching whats in index.html>" reloadable="true"/>
</Host>
In the above Context tag, docBase is the local folder with js and path should match the path placed in index.html.
Doing this you can use the javascript file across all projects without having to add it to resources in the project.
I have created a new Rails 4 project and I am trying to load an external JavaScript file in my HTML file. I have placed the JavaScript file in the /assets/javascripts directory and included the file in my HTML file.
My HTML file:
<html>
<body>
<script src="/assets/hello.js"></script>
</body>
</html>
My JavaScript file:
document.write("test");
I do not see any errors in my web browser console when loading the website. I am pretty sure I put the JavaScript file in to correct directory but the file will not run. Does Rails require something for external JavaScript files to work properly?
I have also tried defining a method in the JavaScript file and calling it within a <script> tag but I get a "Uncaught ReferenceError: methodname is not defined".
You probably need to list 'assets/hello.js' in application.js. The Rails asset pipeline compiles all JavaScript into application.js based on the filepaths that it finds listed there.
More info here: http://railsapps.github.io/rails-javascript-include-external.html
So I figured out why Rails wasn't loading my JavaScript file. When I created the Rails project, it included .coffee scripts which can be used instead of JavaScript. For some reason by default, the .coffee script was being run instead of the JavaScript file that I created. After deleting the .coffee script, my JavaScript loads as expected.
I have one .js file named final.js which I copied as bundle resource I have a requirement like the html document which reads this js file should download at runtime and store it in documents directory. But the js file is not able to read by the html when I loaded it in webview, because of the path of .js file.
I tried with the solution like below, but not worked.
<script src ="./final.js"> </script>
And finally I tried to copy the hardcoded path of application bundle like below, now it worked. Finally I come to know that the path is not proper.
> <script src ="/Users/unknownUser/Library/Application Support/iPhone
> Simulator/7.0/Applications/025EF3B6-F2E6-4162-8921-839D7D98FF58/HTMLGetdataTestApp.app/final.js">
> </script>`
Can any one tell me that how a html file which is stored in documents directory can read a .js file which is stored in main bundle with the correct path instead of hardcoded like above.
The simple solution will be copying the final.js file to documents directory.
Copy the js file from bundle to the document directory (where the html page is located) and set the path as:
<script src ="final.js"> </script>