Sunday, 15 January 2012

java - Ajax request call to the servlet doesn't return anything -



java - Ajax request call to the servlet doesn't return anything -

this jquery function. should pass servlet 2 value , update value. checked if values taken correctly , 2 variables filled correctly. unforuntately don't nil back.

$("#passengers").change(function(event){ var passengers = $("#passengers").val(); var cost = $("#price").text(); $.getjson('pricer', {passengers: passengers, price: price}, function(data){ $("#price").html(data); });

});

here servlet

*/ @override protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string passengers = request.getparameter("passengers"); string cost = request.getparameter("price"); string price_update = new gson().tojson(this.pricerbean.calculateprice(integer.parseint(passengers), float.parsefloat(price))); response.setcontenttype("application/json"); response.setcharacterencoding("utf-8"); response.getwriter().write(price_update); }

the main problem don't error...even one...the javascript console error empty , servlet doesn't show errors

try :

response.setcontenttype("application/json"); response.setcharacterencoding("utf-8"); response.getwriter().write(new gson().tojson(data)); //here info want send

first seek simple :

response.getwriter().write("hello");

in ajax :

$.get('pricer', {passengers: passengers, price: price}, function(data){ console.log(data); });

then seek run , prints post me.

console.log() prints info in browser console.

java jquery ajax servlets

No comments:

Post a Comment