Search code examples
jqueryajaxjira-rest-apijira-pluginjira-rest-java-api

How can I send select2 value to my Java code?


I am developing a Jira Plugin (Servlet & Rest) which is shows project names in a select2 list and when user selects a selection, my datatable will show Issue keys and summaries of them.

The problem is I need the selection of my select list in my Java code. Somehow, I need to send it the selection value inside my Java. Some of my friend give me an advice about using "jQuery.ajax" but I couldn't figure it out how I can do it.

Here is my select2 js code:

AJS.$('#select2-example2').on('click', function () {
 console.log("Selected value: " + AJS.$(this).auiSelect2('val')); });

And I think I need some REST Endpoint in my Java code and I don't know how I can do it either. I need your help about that thing as well.

I know I asked so much questions but I'm new at plugin development stuff and I know I should have develop myself way too much. Thanks already!


Solution

  • Here it is the code

    $('#button').on('click', function(e){
        e.preventDefault();
        let value = $('#sel').val();
      //send the data with post
       $.ajax({
          method: "POST",
          url: "some.php",
          data: value
        })
        .done(function(data) {
                 // if post status is 200
             // code here
            console.log(data);
        });
    });
    <select name="select" id="sel">
      <option value="first" selected>1</option>
      <option value="second">2</option>
    </select>
    
    <button id="button">Click</button>
    
    
    <script
      src="https://code.jquery.com/jquery-3.6.0.min.js"
      integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
      crossorigin="anonymous"></script>