如何在 jsp 中显示 Json 来自 Restlet Server
How to show Json come from the Restlet Server in jsp?
在我的JSP文件中,有一个表单向Restlet服务器发送"POST"请求。然后,Restlet 服务器将返回一个 JsonRepresentation,如何获取 Json 并在我的 JSP 中显示 Json。喜欢这个?但似乎不是工作,为什么?
<div>
<form id="simpleForm" method="post" enctype="multipart/form-data">
<input type="text" name="zi"></input>
<input type="file" class="file" name="tupian"></input>
<input type="submit" value="query"></input>
</form>
</div>
<script>
$("#simpleForm").submit(function(event) {
alert("success");
event.preventDefault();//next, I want to post the form on the up to the Reselet Server and deal with the result come from the server,but the server does not work
$.post("http://127.0.0.1:9192/CalligraphyWordService",$("#simpleForm").serialize(),function(data) {
.......
});
});
</script>
您应该使用 ajax 将数据发送到服务器并获得响应,然后使用该响应更新页面
如果你是JavaScript/Ajax的新手,你最好使用像jQuery这样的库。
jQuery中的简单Ajax帖子看起来像这样:
$.post('url/to/your/reslet', function(json_data) {
var data = $.parseJSON(json_data);
var xxx = data.xxx; // read property of your json object
// then you can use xxx to update your page with JavaScript
});
我建议您禁用提交事件的默认操作并使用ajax异步提交表单。因此,当他们 json 响应时,您可以做任何您喜欢的事情来处理它。如果使用 jquery,代码可能如下所示:
$('your_form_id').submit(function(event) {
event.preventDefault(); // prevent the default action of submit event so that your browser won't be redirect
$.post('your_Restlet_url', function(data) {
// update the page using the passed in data
...
});
});
相关文章:
- 使用来自不同异步函数的响应创建一个json对象
- AngularJS提取物<img>来自JSON
- JS对象->来自jquery ajax的JSON提交->php迭代
- Json显示来自网站的数据显示仅未定义
- 来自JSON数组的Google Maps API生成器
- 使用来自URL的JSON数据来显示谷歌地图标记-如何
- JSON 嵌套 Ul 来自 Javascript 中的单维或多维 json 对象
- 是否可以使用来自Google Contacts API v3的JavaScript,JSON
- 使用来自 Ajax 响应的 JSON 数据数组
- 来自 JSON 字符串的 AngularJS 对象
- 无法解析来自远程服务器的 JavaScript 中的 JSON
- 使用来自AngularJS的Web API JSON响应-错误:应为和数组,但得到了一个对象
- 用来自JSON对象的占位符值替换字符串
- 具有来自静态json文件的路由的主干应用程序(只读)
- jSon到D3js对来自嵌套数组的数据进行分组
- 谷歌地图-来自VB.Net的JSON对象标记
- 显示来自ajax json解析的数据时出现问题
- JSON数据来自未发布的Google Drive电子表格
- 如何在 jsp 中显示 Json 来自 Restlet Server
- 使用Javascript解析JSON.来自Laravel的JSON