3
Programımda kimliğini geçirerek bir işlem yapmam gerekiyor. Kimlik bir kutudan seçiliyor (örn; dinamik olarak değiştiriliyor)) .a ajax.but kullanarak id kimliği geçmek için ilkbaharda denetleyiciden yanıtı geri almak için kod bilmiyorum.bahar çerçevesinde denetleyiciden jsp sayfasına yanıt ajax çağrısı ile denetleyiciye nasıl yanıt verilir
$('#empId').change(function() {
$.ajax({
type: 'POST',
dataType: 'json',
url: 'your_url', // in your controller side (RequestMapping value)
data: 'empId='+$('#empId').val(),
success: function(responseData, textStatus) {
// your stuff here. you found the response in responseData var.
},
complete: function(textStatus) {
},
error: function(responseData)
{
}
});
});
Ve aşağıda bir şey gibi Denetleyiciniz tarafında kod,
@RequestMapping(value = "your_url", method = RequestMethod.POST)
public ResponseEntity<String> postMethod(HttpServletRequest req) {
String jsonString = "";
String empId = req.getParameter("empId");
// your operation done here and
//convert it to json format before sending response.
jsonString = gson.toJson("your response convert here to json format"); // here i used google Gson library to convert your response in json format.
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add("Content-Type", "text/html; charset=utf-8");
return new ResponseEntity<String>(jsonString, responseHeaders, HttpStatus.CREATED);
}
Öyle mi:
// ajax kodu ı ajax yan kod İşte
–@ Ataur Rahman Munna: evet – storm
Bazı örnek kodları yapıştırıyorum. Eğer yardımcı olursa o zaman ans'ı kabul edin. Teşekkürler. –