我想将我的servlet响应分配给javascript中的变量。这是我的html文件:
<html>
<script src="jquery-1.6.2.min.js"></script>
<body>
<h1>TRial</h1>
<p>Select Color:</p>
<select name="color" size="1">
<option value="light">light</option>
<option value="amber">amber</option>
<option value="brown">brown</option>
<option value="dark">dark</option>
</select>
<br><br>
<input type="Submit" id="button"/>
</body>
<script>
var $dataCH = getData();
function getData(){
$.get("SelectBeer.do", function(data) {
var $dataCHUMMA = data;
document.write("Great");
document.write($dataCHUMMA);
return $dataCHUMMA
});
alert($dataCH)
}
</script>
</html>
在脚本标记中:我试图将我的servlet响应分配给变量js。但我无法做到这一点......请帮助我将其分配给全局变量
答案 0 :(得分:3)
var $dataCH;
function getData() {
$.get("SelectBeer.do", function (data) {
document.write("Great");
document.write($dataCHUMMA);
$dataCH = data;
});
}