-2

I would like to assign my servlet response to a variable in javascript. Here is my html file:

<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>

In the script tag: I am trying to assign my servlet response to a variablein js. But I am not able to do it...Please help me in assigning it to global variable

cweiske
  • 30,033
  • 14
  • 133
  • 194
Deepak
  • 432
  • 1
  • 6
  • 15

1 Answers1

1
var $dataCH;

function getData() {
    $.get("SelectBeer.do", function (data) {
        document.write("Great");
        document.write($dataCHUMMA);
        $dataCH = data;
    });    

}
A. Wolff
  • 74,033
  • 9
  • 94
  • 155