Inside HTTP adapter, I am getting JSON object back from REST service. I need to do some parsing of the reply before returning it back to the client.
I figured I can have another JavaScript file to do the parsing, so not to clatter my adapter.js too much.
What I don't know is how to make the 2nd java script file available in my adapter JS.
On client side I would use something like $.getScript("some.js");
JAVA classes can be accessed simply with classpath.className, but I can't find any references on how to load another Java Script file!
Please, help!
You cannot have additional JavaScript files referenced from adapter's JS.
Related
I'm working in a JEE web project and i have a problem, i would like to read and write into a properties file which is located into WebContent/WEB-INF/classes folder and i need to do this with javascript, do you have an idea how to do that ?
Assuming you mean JavaScript on the client: Create an endpoint that the JavaScript code can post to via ajax, and have servlet code handle the post by updating the properties file.
I need to have the functionality in the server side in order to hide the implementetion to the final user.
I didn't find a topic with this kind of solution.
I have a .js file with functions I use within the html5 file.
The js files are "called" in the html by using the script tag, but through the url the user can track them and see the .js file content. I don't want this to happen.
$getScript() does the job, but again the url can be cathched, thus the file content too. Much the same with $ajax function.
Everything work ok, but I want to hide the js content.
The .js file is something like this:
var x, x,....
function A(){...}
function B(){...}
and so on, I use A(), B() functions in the html.
Which is the best approach to get the content file from the server without doing the url visible?
Server: nodejs. (I send some json files through socket.io correctly, but I don't know how to achieve this other issue.
Thanks in advance, best!
If you are sending sensitive information to the client then you are doing it wrong. No matter if the client has the URL to the script, they will still be able to find it if they are determined as long as it is sent to their computer.
Find a different way to accomplish what you are trying to do without sending sensitive information to the client. It is not safe.
i have a c++ file which reads values from a sensor and I want to display those values on a website dynamically. So Im looking for a way to pass these values(integers) from my cpp file to an javascript which displays them on the site.
My first, simple try was to write the values into a js file as variables every second from my cpp script. The Js then uses this file as a source and displays its variables on the site:
cpp:
fprintf(file, "var mx=%d, my=%d, mz=%d, ax=%d, ay=%d, az=%d, gx=%d, gy=%d, gz=%d;\n",
imu.raw_m[0], imu.raw_m[1], imu.raw_m[2], // M = Magnetometer
imu.raw_a[0], imu.raw_a[1], imu.raw_a[2], // A = Accelerometer
imu.raw_g[0], imu.raw_g[1], imu.raw_g[2] // G = Gyroscope
);
html/js:
<script src="./imu.js" type="text/javascript"></script>
The Problem now is of course, that I need to refresh the page all the time, because the imu.js file is cached by the website.
I'd rather have a way to directly pass to integers from the cpp file to the js script. I read something about json or Googles V8 script. But I'd like to hear your suggestions first.
By the way, Im running this on a raspi, if this is important.
Thanks for your help
EDIT:
I'm goning to try it with a mysql database, in which my cpp file writes the data from the sensor with Connector/c++ from http://dev.mysql.com/doc/connector-cpp/en/ and my website reads them.
You could compile your C++ code into a Node.js plugin, you can then register a JavaScript function with your plugin which the C++ calls when it updates the value. That way you can pass values directly from C++ into Javascript in a managed and controlled way.
Node.js has the added benefit of being able to host your webpage and do all the Websocket and HTTP stuff that can be a pain in C++.
You do not have to refresh if your script is smart about how to access the data file! In case you do have a webserver at hand: Take care that your data file is accessible by your webserver and then let your script request the file via ajax (link to w3schools)
I'm doing something similar on a BeagleBone Black. With websocketd you can turn pretty much any program into a websocket endpoint and then send data via stdin and stdout commands. This would be a particularly good solution for you since websockets are designed to handle information that's constantly changing.
I have a login.fcc page which I want to modularize into Javascript,CSS & HTML modules so that it can be maintained easily.
As you know in Siteminder FCC pages we have number of Attributes which we can access and write code accordingly.
When I try to pull this $$smauthreason$$ in seperate js file I am not able to access the attribute value.(this value shd be set by siteminder when this fcc page is called).
Any ideas why I am not able to put this javascript code in seperate js file?
SiteMinder web agent will only serve .fcc files. If you have another file (.js) you must host it on another server instance, but you will not be able to access the SM attributes from it.
As stated before, the FCC file is the only file processed by the web agent,so you can't do the variable substitution in other files.
I think probably what i'd suggest is binding all the variables to 'global' javascript variables in your fcc file. This would allow you to import javascript source files into the HTML that would have access to the variables, but as javascript variables and not $$USER$$,etc type variables.
The other thing you might play with (and I have not done this) is to try server side includes if you're using apache. If the server side includes are processed BEFORE the fcc handler, then you might be able to modularize more.
So i'm very new to xml to javascript so i thought I would learn from w3schools, but this site
http://www.w3schools.com/xml/xml_to_html.asp shows an example that I can't mimic locally. I copy/pasted the .js and downloaded the xml but I just get a blank screen!
It's working in there try it yourself but not for me? Do I need it on a server or something?
Yes, that code retrieves the XML data from a web server using AJAX. Since you don't have a server running locally, you can change the URL to point directly to the w3school's version:
xmlhttp.open("GET","http://www.w3schools.com/xml/cd_catalog.xml",false);
Alternatively, play around on their online version ;)
well i guess you have to add the example xml (cd_catalog.xml) to your file system. and you definitively have to access the html file on a server (apache i.e.)
First, ensure that both HTML file (with the Javascript block in it) and XML file are placed in the same directory.
Next, you probably need to place those files under your local web-server and open the HTML like this:
http://[local server host]/ajax.html
instead of opening the file directly from e.g. Windows Explorer:
C:\[path to the file]\ajax.html
For the latter case you'll get an "Access is denied" error.
-- Pavel
Are you running this under a web server or just creating a couple of text files and loading them in your browser?
The "GET" request this relies upon could possibly be failing.
Use Apache or another similar HTTP server and run the example as if it were hosted on the web.