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"
I am trying to download the content of a javascript file from a CDN imperatively within a typescript file so that I can make use of it in the correct lifecycle hooks, and so that I can ensure it is only downloaded when it is first needed.
For example the googleCDN to download Jquery:
I do not want to add the library src to my index.html page, and I do not want to add it to my angular.json configuration file because I do not want to use this library in many places in my app, and so I do not want to always force my users to download it.
I have been experimenting with the HttpClient.JsonP method because the CDN server I am trying to request the library from is enforcing CORS, however, I believe that because the response is not JSON, rather a function, it doesn't work.
example code:
load<T = any>(): Observable<T> {
return this.http
.jsonp(
'https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js',
'callback'
) as Observable<T>;
}
with the error:
"JSONP injected script did not invoke callback."
That error makes sense I think because the response is not JSON and is not wrapped in a function like a browser expects.
I am now trying a similar technique as here:
https://gist.github.com/zainzafar90/1f58a4a04ac17fcf8e7424a053620822#file-dynamic-script-loader-service-ts
But I really don't like this as I believe I will have to augment a global variable with this, although I don't know how as of yet.
I want to use shopify js buy sdk with wordpress. I've downloaded the sdk files and follow the steps as described in the documentation
import Client from 'shopify-buy';
const client = Client.buildClient({
domain: 'your-shop-name.myshopify.com',
storefrontAccessToken: 'your-storefront-access-token'
});
But It always give an error, which says import declarations may only appear at top level of a module.
So I've keep it at the top and add type="module" at the script tag. then the error is solved, but javascript code within this script is not working...
So, can anyone tell me what can I deo to solve this problem?
If you aren't using any of the Node or JS package managers then try using the UMD package available on their documentation page:
<script src="http://sdks.shopifycdn.com/js-buy-sdk/v1/latest/index.umd.min.js"></script>
You can use it like any other js script, it exposes a global window.ShopifyBuy factory.
Then use it like this:
const client = window.ShopifyBuy.buildClient({
domain: 'your-shop-name.myshopify.com',
storefrontAccessToken: 'your-storefront-access-token'
});
I'm using Ecmascript 3 on Rhino JavaScript engine. The process starts with connecting a remote server and download scripts from there.
I need to import my JavaScript libraries that would work on Linux agent like this:
/*
#import lib/*.js
*/
init(this);
function init(){
var foo = lib.foo;
var constants = lib.constant;
////some logic here
}
So, my script agent tries to download script files from server, and it needs to import all of the libraries that I wrote up.
I already tried to use lazy loading but it's too hard to implement all files right now and idea, how could I simplify this process?
I have a Django application, which requires several JavaScript files.
In Chrome I get the error "Resource interpreted as Script, but transferred with MIME type text/html".
AFAIK (see 2) in order to fix this problem, I need to configure Django so that JavaScript files are returned with content-type "application/x-javascript".
How can I do this in Django?
UPDATE: I followed the advice by Daniel Roseman and found following solution.
1) Modify urls.py:
urlpatterns = patterns('',
...
url(r'.*\.js$', java_script),
...
)
2) Add following function to views.py:
def java_script(request):
filename = request.path.strip("/")
data = open(filename, "rb").read()
return HttpResponse(data, mimetype="application/x-javascript")
I had an issue with Django serving javascript files as text/plain with the included server, which doesn't work too well with ES6 modules. I found out here that you could change file extension associations by placing the following lines in your settings.py:
#settings.py
if DEBUG:
import mimetypes
mimetypes.add_type("application/javascript", ".js", True)
and javascript files were now served as application/javascript.
I suspect the problem is not what you think it is. What is probably actually happening is that your JS files are not being served at all: instead, the Django error page is being sent. You need to figure out why.
Expanding on Alexandre's answer using put the below code into settings.py of your main project. After that you will need to clear your browser cache (you can test it by opening an incognito window as well) in order to get the debug panel to appear.
if DEBUG:
import mimetypes
mimetypes.add_type("application/javascript", ".js", True)
Since this doesn't prevent scripts from being interpreted correctly by the browser, why is this a problem? runserver is only for development (not production use), and as such is not a full blown web server.
You should continue to use it in development and when you move to production configure your webserver appropriately for static files.
However, if you absolutely must use the development server to serve static files; see how to serve static files.
For Django use request context in views :
return render_to_response('success.html', {'object': varobject},context_instance=RequestContext(request))
I ran into that error today even after adding #piephai s solution to my settings.py. I then noticed that #Daniel Roseman got it right as well:
My import paths were wrong, I had to add ".js" to all of them, for example:
import {HttpTool} from "./requests"; became import {HttpTool} from "./requests.js";
Makes sense after thinking about how routes for static files are generated.
The solution to the problem is describe in the documentation
For Windows, you need to edit the registry. Set HKEY_CLASSES_ROOT\.js\Content Type to text/javascript.