jquery和servlet如何传递json?
例 3.6
<html>
<head>
<script src="jquery.js"></script>
<script type="text/javascript">
function getP(id) {
$.getJSON("jqueryservlet36", {
id : id
}, function(obj) {
for ( var p in obj) {
//Servlet 返回值是{type:'"+type+"',price:'"+price+"'}"这样的JSON对象
//$("#info").toggle();找id为info的元素
$("#" + p).html(obj[p]);
/* document.getElementById(p).innerHTML = obj[p];和下一句一样。
$("#"+p).html(obj[p]);
*/
}
})
}
</script>
</head>
<body>
<table width="340" border="1">
<tr>
<td id="1" οnclick="getP('1')">点这1</td>
<td id="2" οnclick="getP('2')">点这2</td>
</tr>
</table>
<table width="340" border="1">
<tr>
<td width="170">参数项</td>
<td width="170">参数值</td>
</tr>
<tr>
<td>型号</td>
<td id="type"> </td>
</tr>
<tr>
<td>价格</td>
<td id="price"> </td>
</tr>
</table>
</body>
</html>
package helloWorld;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44594371/article/details/103063415
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义