javascript - Ajax can not send a request other than GET -
i can not. 4 days have been struggling send data ajax using different method , can not advise. create project in spring boot. have created mapped address controller
@putmapping(value = "/changeemail") public boolean changeemail( @requestbody changeemaildto changeemaildto ) { system.out.println("email: " + changeemaildto.getemail()); return true; }
this controller supposed accept email address sent ajaxa
function changeemail() { console.log("event"); $.ajax({ type: 'put', url: '/changeemail', data: { email: $('#email').val() }, success: function (result) { console.log('function'); } }); }
however, effect in console crashes me
put http://localhost:8080/signin net::err_too_many_redirects send @ jquery-3.2.1.min.js:4 ajax @ jquery-3.2.1.min.js:4 changeemail @ settings.js:58 submithandler @ settings.js:52 d @ jquery.validate.min.js:4 (anonymous) @ jquery.validate.min.js:4 dispatch @ jquery-3.2.1.min.js:3 q.handle @ jquery-3.2.1.min.js:3
the dto has 1 field
public class changeemaildto { @isvalidemail @existsemail(ifexistsreturn = false) @getter @setter private string email; }
after trying send data via ajax, sends me error controller
@controller public class pagenotfoundcontroller implements errorcontroller{ @requestmapping("/error") public modelandview showpageerror() { return new modelandview("redirect:/signin"); } @override public string geterrorpath() { return "/error"; } }
screen browser tool send , receive: https://zapodaj.net/f1b8ed0b2a16b.png.html mentioned, controller can correctly pick query ajax only. every time flips on error controller. additionally, if wanted send data directly form, there no problem query. ajax divert, not know.
Comments
Post a Comment