提问跨域传递json无法获取

 

var result = {
userId: "1",
tmplId: "402856767d124807017d129c56390eab",
code: 200,
message: "ok",
};

$.ajax({
type: "post",
// url: "http://127.0.0.1:7001/leswfeInst/instCreate",
url: "/leswfeInst/instCreate",
data: JSON.stringify(result),
contentType: "application/json",
// dataType: 'JSON',
dataType:'JSONP',
async: false,
success: function (result, e) {
console.log(result);
console.log(e);
task = result;
}
});
//正常获取json
@RequestMapping(path = "/leswfeInst/instCreate", method=RequestMethod.POST)
public Map<String,Object> response1(@RequestBody Result result){
Map<String,Object> re = new HashMap<>();
re.put("code",200);
re.put("msg","成功");
return re;
}

当我将url改为url: "http://127.0.0.1:7001/leswfeInst/instCreate",时,先报出需要get获取资源(post是新建资源),
Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported]
我改,再报出
Resolved [org.springframework.http.converter.HttpMessageNotReadableException:
Required request body is missing: public java.util.Map<java.lang.String,
java.lang.Object> com.juezee.oatest.controller.ArchiveController.response1(com.juezee.oatest.entity.Result)]


大佬们有没有跨域传递json的好办法?
请登录后发表评论