Bir HTML formundan veri yakalamaya ve MVC denetleyicisine göndermeye çalışıyorum ancak aşağıdaki kod çalışmıyor. Birisi bana burada yardım edebilir.JSON verilerini ajax çağrısından MVC denetleyicisine gönderemiyor
var form = JSON.stringify(jQuery('#project_form').serializeArray());
$.ajax({
contentType : "application/json; charset=utf-8",
dataType : "json",
type: "POST",
url: "/SE/doLogin",
data: form,
success: function(response){
window.location.href = response;
Ve burada
@RequestMapping(value = "/doLogin",method = RequestMethod.POST,consumes = "application/json",produces="text/plain")
@ResponseBody
public String sayHello(@RequestBody TestDao templateModel){
System.out.println("say");
System.out.println(templateModel.getEmail());
TestMethod t1 = new TestMethod();
t1.getValues();
return "newsFeed";
}
Ben herhangi bir argüman tutmak değilim, nasıl çalıştığını ve S.o.p konsolda basılmış oluyor benim denetleyicisi olduğunu. @RequestBody çalışmıyorken emin değilim.
Ve TestDao ve Json verileriniz nasıl görünüyor? – starcorn
@starcorn Json veri formatını işaretlediğiniz için teşekkür ederiz. Bence bununla ilgili bir sorun var. 'dan sonra var biçim = JSON.stringify (jQuery ('# project_form'). SerializeArray()); Json'ı 'un altında alıyorum. [{"name": "email", "value": "kala"}, {"name": "password", "value": "kala"}] Bunu nasıl düzeltebiliriz? –