Access python method from plain javascript [duplicate] - javascript

This question already has answers here:
Call Python function from JavaScript code
(6 answers)
Closed 3 years ago.
I have this python method shown below in a separate file and want to access and get value using plain js (no frame works used.) is there any way i can achieve this?
def myPythonCode :
....
...
return somevalue

You can use python wrapper for google V8 engine called PyV8
It act as a bridge between the Python and JavaScript objects, and support to hosting Google's v8 engine in a python script.

Related

Symbol behind the .js [duplicate]

This question already has answers here:
Why pass parameters to CSS and JavaScript link files like src="../cnt.js?ver=4.0"?
(9 answers)
Closed 3 months ago.
What is "?_=3.5-SNAPSHOT-Dev" mean after ".js"? I do some research on google but no idea what it mean and what it use for
<script type="text/javascript" src="js/jquery-3.5.1.js?_=3.5-SNAPSHOT-Dev"></script>
It depends on the server that's serving your Javascript. Generally, variables like those on JS files are used for cache busting. I think in your example, 3.5-SNAPSHOT-Dev could be a release tag. If this JS file is now on your own machine, you can safely discard the ? and anything after that. If you're getting this from another server somewhere, seek out documentation about that server to see what they use the _ variable for.

Java server (Tomcat 9.0.48) Ignores ${} this expression [duplicate]

This question already has answers here:
${} template literal (ES2015) conflict with JSP EL syntax
(2 answers)
Closed 1 year ago.
I am relatively new to Java web-development and I'm trying to execute JavaScript code in a JSP file, i.e ${(format.date)}, but when I view the source code on my web-browser it completely ignores the expression ${}.
Any particular reason why the server is ignoring it? How do I overcome this?
<Script>
${(format.date)}
</Script>
FYI: format.date is just a random syntax but the server would still ignore anything that would be inside curly brackets.
The server ignore the syntax, because it doesn't find a variable in any scope.
<c:set var="pattern">MM/dd/YYYY</c:set>
<fmt:formatDate value="${format.date}" pattern="${pattern}"/>

I want to access a javascript variable in my HTML in my main node js file [duplicate]

This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 2 years ago.
function takePic(){
var dataURL = canvas.toDataURL();
}
So i have this function in a script tag nested in my HTML. I have a separate js file to start the server. My problem is I want to use this variable/data in my js file but I don't know how to access it.
Hmmm sounds like you need to send the variable data across the internet from your html webpage to your node.js server. To do that you could look into using socket.io to send data back and forth.

How do I include a HTML file and write it out via javascript? [duplicate]

This question already has answers here:
Javascript read html from url into string
(4 answers)
Closed 7 years ago.
I'm using CodeKit and would like to continue to do so, and thus I haven't got any access to PHP. So what I would like to do is basically include a plain external .html file locally or on the codekit server with javascript.
The idea is to have an if statement and if foo=true then write out foo.html, else write out no-foo.html.
How do I do this?
Provided you have jQuery tagged in your question, you can use it's $.get implementation, which is a higher level version of the $.ajax function except $.get is limited to GET requests, which is likely what you need.
When using Ajax, you're sending an asynchronous HTTP request to something on the server, this may be a HTML document, or chunk of HTML code, anything that the server responds with on a specific request can be used.
$.get('/data/foo.html', function(data){
$('.bar').html(data);
});

ASP.NET - Having a common script for both client-side and server-side? [duplicate]

This question already has answers here:
Embedding JavaScript engine into .NET [closed]
(21 answers)
Closed 7 years ago.
I am working on a web application and I come to this calculation method that is going to take a string and returns the number of SMS messages.(It's a pure function and doesn't need any external resources to do its job)
I need this function to work both in client-side and server-side.While in client-side user can see the number of SMSs of his message so far and when in server-side i have to calculate how much does the message cost.
I thought that I had to have a C# version of this function for server-side and a javascript one for client-side but then I thought DRY - what if I could run javascript functions in server-side too ?
I am not sure if it's possible or not ?
So here's the question : can we run a javascript function in server-side (or in my case from a class library)?
I think you're looking at this from the wrong way. Instead of trying to run javascript server side (which is not possible I think), you should create a C# function to calculate whatever it is you want calculated and pass the result to your client. This function can be invoked by the client through e.g. an ajax call, or passed in through a viewmodel etc.
Solution:
1. You should write API in C# and since it is pure method to calculate, its number of parameters are fixed. Now Client side code can make ajax (or xmlHttpRequest) to this API and response to which can be handled at client side.
2. Use Node for server side javascript something like, https://www.npmjs.com/package/sandbox, or use native node js VM module.

Categories

Resources