how do I manage to execute a Python-file or a bash-script on a server via a press of a html-button without using a framework?
I have tried several versions of Ajax-Calls suggested in answers to similar questions, but none of them seem to work for me.
Note: Im using an Apache-Server on a RaspberryPi
According to apache documentation, you should configure apache to run CGI script, define an url prefix that maps a directory that contains your script and finally your script must return output in a particular way, or Apache will return an error message.
So, for example, if you define an url prefix like:
ScriptAlias "/cgi-bin/" "/path/to/your/script/cgi-bin/"
you can create a simple anchor to execute your script, you don't need to use ajax for this.
click me
To successful run your script you should follow apache directive in "Apache Tutorial: Dynamic Content with CGI"
Related
I am developing a SAPUI5 mobile app using cordova. Now I need to include another library (cordova-plugin-file) into my project. I've already tried to do this, but my problem is, that if the plugin is included, my 'sap-ui-core.js' file tries to load 'library-preload.json' (see screenshot).
screenshot console
And I do not want to load a library-preload.json. How could I solve this problem?
An Answer on how to solve this problem by adding a 'library-preload.json' file
would also not be bad :)
Set the data-sap-ui-preload="" in SAPUI5 Boostrapping.
To Quote from Source:
The library-preload.json files which contain all controls from a
library to reduce the number of HTTP requests are not required in
hybrid apps because there is no HTTP latency. SAPUI5 will by default
try to access them, so you might see a failed attempt to load these
files in the log file or developer tools. These error messages do not
hurt, though, and you can get rid of them by declaring that no such
files exist and by setting the following configuration in the SAPUI5
bootstrap script tag:
`data-sap-ui-preload="" `
Read: https://sapui5.netweaver.ondemand.com/sdk/#docs/guide/293eb945f0e945aaa776812481b4c533.html
Preload has 3 more variants. Read More here:
https://help.sap.com/saphelp_nw74/helpdata/en/91/f1cea36f4d1014b6dd926db0e91070/frameset.htm?original_fqdn=help.sap.de
I'm running a Node.js server along with an Angular frontend. One of the Angular dependencies I'm using requires me to import a javascript file into my html page, by the name of swing.js. However, when I try to do this, it sends the required file as an http request to the server, resulting in requests that look like the following:
http://localhost:3000/home/me/app/node_modules/angular-swing/dist/swing.js
Obviously, this comes up as a 404. As an alternative, I've tried changing
<script src="/home/me/app/node_modules/angular-swing/dist/swing.js"></script>
into
<script src="swing.js"></script>
and then on the server-side, doing:
app.get('swing.js', function(req, res){
res.sendFile('home/me/app/node_modules/angular-swing/dist/swing.js');
});
This works a little more, but then the file doesn't run properly, as I'm assuming it's no longer in the npm environment it needs to be in. I've tried multiple iterations of changing
<script src="/home/me/app/node_modules/angular-swing/dist/swing.js"></script>
into something that uses periods (.) to represent more relative paths, but that doesn't appear to work either. Overall, I'm very stuck, and would appreciate any insight. If it's of any use, I'm also using:
app.use(express.static(__dirname+'/public'));
Making my comments into an answer...
node.js does not serve any files by default so any script files that you need sent from your server to the client upon request need an explicit route to handle them or they need some generic route that knows how to handle all the requested script files.
swing.js in the client is not part of any "NPM environment". It's running the browser at that point, not in any NPM enviornment. It's possible that swing.js itself needs some other scripts or resources that also need routes and that's why it doesn't work after you make an explicit route for it. You can probably examine the specific errors in the console to give you a clue why it isn't working.
You may also want to read this: How to include scripts located inside the node_modules folder?
Is there a simple way to include a remote js file on the fly (in an onclick function)?
The "verify" onclick event for our ssl site seal requires a code include from the vendor. Trouble is, it slows loads times. So I extracted the function from their js and hosted it locally - but they change the request params from time to time so I have to manually edit the js.
It would be nicer if I could just include the remote file when someone clicks the site seal.
TIA.
If you are using jQuery you can use $.getScript
Description: Load a JavaScript file from the server using a GET HTTP request, then execute it.
You can use the createElement() and add it to the DOM. Please see the below document.
http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS
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.
I have some javascript that looks like this:
$('.resultitem').click(function(event){
alert('check this gets called');
location.href='viewinfo/'+$(this).attr('rel');
});
this code works fine on my local machine but after uploading to the server it doesn't seem to get called at all. Can anybody help me understand why?
UPDATE: As mentioned below this was caused by a script error higher up. While debugging with firebug, I noticed on the server that in the net tab a GET jquery.cookie.js failes with a code of 406 not acceptable.
I had to rename to jquerycookie.js to keep this particular hosting provider happy. I did a little more research and this could be due to the following:
"anything with .cookie. in it triggers an Apache mod_security warning, stopping the file from being served, effectively making this unable to work"
Are you including your JavaScript files using Cake's HTML helper? For example:
echo $this->Html->script(array('jquery-1.4.3.min'));
Note that following Cake's conventions, I've left off the .js file extension. In my experience, this has created problems where the production server thinks that .min is the file extension and attempts to load a nonexistent file called jquery-1.4.3.min, which means jQuery isn't loaded and therefore the snippet you've posted would fail.
I'm not sure if this is how you're loading your scripts, but in general it's safer to use the entire file name, like so:
echo $this->Html->script(array('jquery-1.4.3.min.js'));