0

i would have need some tips/help here. I have nearly 0 experience with jquery but i might need it.

in my controller i have this :

@RestController
public class mainController {

@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(Model model) throws IOException, GeneralSecurityException {
    DriveQuickstart drive = new DriveQuickstart("c:/temp/credentials.json");
    String res = drive.checkFile("cwg");

    return res;
}

for now, i succeeded to display the res in my view with jquery get. But i need to go further.

in my view (index.html), i need to pass the parameter with (jquery method?) a form and display the res.

like :

    @RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(Model model) throws IOException, GeneralSecurityException {
    DriveQuickstart drive = new DriveQuickstart("c:/temp/credentials.json");
    String res = drive.checkFile("***HERE PARAMETER***");

    return res;
}

I probably needed a POST ans GET method. but i have no idea how to achieve that. How to pars parameters to a controller method via html.

thx very much

2
  • Please, check this tutorial Commented Jan 29, 2019 at 15:32
  • thats nice to put -1 and not answered at all thx very mutch ... Commented Jan 29, 2019 at 19:58

1 Answer 1

2

In this case, you need to modify your method as below

@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(@RequestParam String inputParameter) throws IOException, GeneralSecurityException {
    DriveQuickstart drive = new DriveQuickstart("c:/temp/credentials.json");
    String res = drive.checkFile(inputParameter);
    return res;
}

The section modified is Instead of Model model we used @RequestParam String inputParameter as an argument.

and from JQuery call this GET method and pass param as QueryString


Update: Your JQuery Method should similar to this:

$("input").keyup(function(){

  $.ajax({
    url: "/index",
    type: "get", //send it through get method
    data: { 
      inputParameter: value , // your get parameter(s)
      inputParameter2: value2, 
      inputParameter3: value3
    },
    success: function(response) {
      //Do Something on successful Ajax call
    },
    error: function(xhr) {
      //Do Something to handle error
  }
  });


});

refer to the below links:

Sign up to request clarification or add additional context in comments.

1 Comment

Hello, i almost got it, but here i have done : i have : the get $.get("/index",{"query": que}, function .... and i catch up the parameter "que" with input val(). but here the issues, the get is trigged only once. how to trigged $.get again ? i tryed this but with no succes : $( "input" ) .keyup(function() { var value = $( this ).val(); $( "p" ).text( value ); }) .keyup();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.