Http Server (Java on Vertx) not getting POST parameter -


i sending ajax request client such as:

<!doctype html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script> $(document).ready(function() {         $.ajax({         url: "http://192.168.1.74:8888",          type: "post",         data: ({username: 'bobby'})      }); }) </script> </head> <body> </body> </html> 

my http server written in java utilizing vertx so:

public class main extends abstractverticle {     @override   public void start() throws exception {          vertx.createhttpserver().requesthandler(new handler<httpserverrequest>() {         @override         public void handle(httpserverrequest request) {            system.out.println(request.getparam("username"));              }     }).listen(8888);    } } 

every time run client, server writes console request sent, server says value null. doing wrong? how read post parameter being sent client?

update:

i found problem, no solution. if change ajax post appear. how make works post , not get? opposite of occurring now?

cheers

data: {"username": 'bobby'} fix issue, , remove () can try change ajax request in jquery follow

var datavar = {username:"someusername"}; //array   $.ajax({     url : "ajax_post_url",     type: "post",     data : datavar,     success: function(data, textstatus, jqxhr)     {        alert("success") ;      },     error: function (jqxhr, textstatus, errorthrown)     {  alert("fail") ;      } }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -