How to pass variable values from java to javascript
$.ajax({
url: "YourSeveletPathName",
type: 'GET',
success: function(response) {
//console.log(response);
//map your data here - to series parameter in your highchart method.
},
error: function(error) {
errorFunction(error, parameter);
}
});
How to pass variable from java to javascript?
You need to use @ResponseBody and inside the ajax use the success
callback to get the value of success of ajax.
DataTypeOfReturn
is the type of the data which you want to return & it can be int/String
function edit(id) {
jQuery.ajax({
type: "GET",
url: "getId",
data: "id= " + id,
datatype: "text",
success: function(data) {
console.log(data)
}
});
var type = <%= ((String)request.getAttribute("myType"))%>;
console.log("type is " + type);
}
@RequestMapping("/getId")
public @ResponseBody DataTypeOfReturn getId(
@RequestParam int id, HttpServletRequest request) {
int idBook = id; // add data type here to avoid java error
System.out.println("get id book " + id);
String type = BookDao.getTypeCategory(id);
request.setAttribute("myType", type);
System.out.println("request attribute" + request.getAttribute("myType"));
return theValue; // value which you want to return
}
Pass variables from java to javascript
Would recommend following:
Install apached tomcat
http://tomcat.apache.org/tomcat-6.0-doc/appdev/Try Hello World example included in Apached Tomcat
http://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/
You would find values in variables shown in GUI.
Next Step assigning java variables to javascript variables, use following syntax
<script type="text/javascript">
var jsVariable =<%javaVariable%>;
</script>
Hoping this helps.
Cheers !!
Passing value from java to Javascript
Could you do it thru WebView.evaluateJavascript()?
https://developer.android.com/reference/android/webkit/WebView.html#evaluateJavascript(java.lang.String,%20android.webkit.ValueCallback%3Cjava.lang.String%3E)
So with that you could send simple CustomEvent to document in WebView
webView.evaluateJavascript("document.dispatchEvent(new Event('printer_error', { details: "No printer found!" }));");
and in JavaScript you can hook listener for your custom event to react.
document.addEventListener('printer_error', e => alert(e.details));
Didn't test this so might be that at least evaluateJavascript() needs callback function.
How to pass data from Java to a JavaScript web application?
If you assume that the web page is always going to be viewed on the same machine that is running the JavaFX application you could always have it export the file via HTTP (using Jetty or similar), then have the web page load the data using a URL such as "http://localhost:port/fileContainingData".
Pass jsp variable to javascript
Another way to do it:
<input type="hidden" value="${s.status}" id="status">
<script>
var status = document.getElementById('status').value;
</script>
how to pass a java variable to javascript
use inline script for example:
<script type="text/javascript" >
var d1 = [];
for (var i = 0; i < 14; i += 0.5) {
d1.push([i, Math.sin(i)]);
}
var d2 = [[0, 3], [4, 8], [8, 5], [9, 13]];
// A null signifies separate line segments
var d3 = [[0, 12], [7, 12], null, [7, 2.5], [12, 2.5]];
$.plot("#placeholder", [ d1, <%=otp1%>, d3 ]);
// Add the Flot version string to the footer
$("#footer").prepend("Flot " + $.plot.version + " – ");
</script>
Related Topics
How to Implement Ping/Pong Request for Websocket Connection Alive in JavaScript
React Import: Navigate One Folder Up
No Overload Matches This Call. Type 'String' Is Not Assignable to Type 'Signals'
How to Hide Blinking Cursor in Input Text
Can We Insert JavaScript into Any Webpage Loaded in the Browser
Call Method That Inside Another Component - React Js
Onchange Is Not Triggering in React Js
Will a React Component Re-Render If Its Props Are Updated, But Don't Change in Value
Bootstrap Modal Hide Not Working With Jquery Ajax
How to Select Id and Get a Value of It in Input Data in This Row
Convert a Flat Json File to Tree Structure in JavaScript
Can We Call the Function Written in One JavaScript in Another Js File
How to Format a Number to 2 Decimal Places, But Only If There Are Already Decimals
Detect Click into Iframe Using JavaScript
Image Upload With Preview and Delete Option - Javascript/Jquery
Display Data Label (Legend) in Line-Chart Using Chartjs
Google Firestore - How to Get Several Documents by Multiple Ids in One Round-Trip