Vla*_*sky 4 java ajax spring spring-mvc
我有像这样的ajax json POST方法
$.ajax({
type: 'POST',
url: "localhost:8080/webeditor/spring/json/",
data: JSON.stringify(contents),
dataType: "json"
});
Run Code Online (Sandbox Code Playgroud)
控制器处理发布请求
JSONPObject json;
BindingResult result = new BeanPropertyBindingResult( json , "MyPresentation" );
@RequestMapping(value="json/", method = RequestMethod.POST)
public void savePresentationInJSON(Presentations presentation,BindingResult result) {
//do some action
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误
XMLHttpRequest无法加载localhost:8080/webeditor/spring/json /.仅支持HTTP的跨源请求.
我不确定如何纠正上述错误.
我的最终作品版本
var jsonfile={json:JSON.stringify(contents)};
$.ajax({
type: 'POST',
url: "/webeditor/spring/json/",
data: jsonfile,
dataType: "json"
});
Run Code Online (Sandbox Code Playgroud)
AJAX,和
@RequestMapping(value = "/json/", method = RequestMethod.POST)
public void saveNewUsers( @RequestParam ("json") String json)
{
System.out.println( json );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37034 次 |
| 最近记录: |