0

I would like to send value of a <li> to server side using jQuery $.get.

HTML:

<div style="position:relative">
<ul id="myid" class="myid">
<li id="myid"><a>test</li>
</ul> 
</div>
<div id="somediv" style="position:relative">hello</div>


    <script>
        $(document).on("click", "#myid", function() { 
            $category = $('#myid li').text();
            $.get("someservlet", function($category) {  
                $("#somediv").text(responseText);          
            });
        });
    </script>

In server side, the request parameter is absent. How is this caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
hiboss
  • 317
  • 6
  • 15
  • Please read the api docs on how to send data with `$.get`. you aren't sending `$category` and there is no `responseText` defined so you should see console errors – charlietfl Apr 17 '16 at 15:29
  • Duplicate of http://stackoverflow.com/q/15576548 After that, this is most likely helpful for general use cases as to servlets and ajax: http://stackoverflow.com/q/4112686 – BalusC Apr 17 '16 at 15:30
  • @BalusC hi, appreciate that you show these link. however, none of them actually helped me as i want to pass my
  • value to my servlet when it is clicked.
  • – hiboss Apr 17 '16 at 15:42
  • Both links show how to pass request parameters with jQuery Ajax. That the request parameter itself is coming from `
  • `'s text content is irrelevant to the problem. You'd have had exactly the same problem when hardcoding it like so `$category = "test";`.
  • – BalusC Apr 17 '16 at 15:43
  • @BalusC ok i managed to get value to pass to my servlet, However it pass all available value of
  • instead of selected.
  • – hiboss Apr 17 '16 at 15:52