javascript - AJAX call returning 404 error due to incorrect content type -


ajax call returns:

http status 404 - /mycustomproject/en/web-inf/views/desktop/register/region.jsp

incidentally, same url using make ajax call.

$( "#address\\.country_del" ).change(function() {       alert( "handler .change() called." );       $.ajax({           url: '/register/region',           data:            {               country: $("#address\\.country_del").val()           },            type: "post",       }).done(function (data){});     }); 

controller:

@requestmapping(method = requestmethod.post, value = "/region") public list<regiondata> getregion(@requestparam(value = "country") final string country) {     final string isocode = country;     final list<regiondata> regions = i18nfacade.getregionsforcountryiso(isocode);     return regions; } 

my request , response seen on browser: enter image description here
i think problem content type of response ?!

the issue here view resolver can see response controller class resolved jsp

http status 404 - /mycustomproject/en/web-inf/views/desktop/register/region.jsp

so need let method in controller know needs return json

you can annotating method @responsebody

@responsebody, return object body, in format specified in produces="application/json".

@requestmapping(method = requestmethod.post, value = "/region" ,produces="application/json")  @responsebody public list<regiondata> getregion(@requestparam(value = "country") final string country)   {     final string isocode = country;     final list<regiondata> regions = i18nfacade.getregionsforcountryiso(isocode);     return regions; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -