java - Calling servlet to load the data using jquery ajax? -
i new jquery. have servlet fetch data database , result kept request , same result retrieved in jsp file. have call servlet using ajax jquery load data. doing below. not loading. please me.
$('#myform #revert').click(function() { $.ajax({ type: "get", url: "./mycontroller", success: function(msg) { <span style="color:green;font-weight:bold">successful</span>'); }, error: function(ob,errstr) { //todo } }); });
servlet code:
//service call gets data , result kept in request scope below request.setattribute("myresult", result); request.getrequestdispatcher("/web-inf/myscreen.jsp").forward(request, response);
thanks!
ajax not normal httprequest
,you canot forward or sendredirect
ajax request
since asynchronous,you need write response ajax request
printwriter out = resp.getwriter(); out.println(resultstring); return;
please read @balusc great answer :how use servlets , ajax?
Comments
Post a Comment