iframe ajax

		var urlStr = "http://127.0.0.1:8089/PrjJsp/SkyonJsonSave";
		var a = new Object();
		a.b = arr;
		
		var obj = JSON.stringify(a);
		console.log(obj);
		
		//
		var result = $.ajax(
		{
			type:"POST",
			url:urlStr,
			data:obj,
			dataType:"jason",//此处要设置成jason
			contentType: "application/text; charset=utf-8",
// 			async:false,
// 			async: true,
			success: function (data)
			{
				return false;
// 				alert(data);
// 				document.getElementById("btnSave").interHTML = data;
			}
		});
		
		var strResult = result.responseText;
		alert(strResult);
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		try
		{
			// 获取requestContext
			String reqContext = readJSONString(request);

			// 转换JSONObject
			JSONObject jsonObj = JSONObject.fromObject(reqContext);//转换成JSONObject
			System.out.println(jsonObj);
			
//			JSONArray jsonObj = JSONArray.fromObject(reqContext);
//			System.out.println(jsonObj);
			
			
			//
			response.setCharacterEncoding("utf-8");
			response.setContentType("application/json; charset=utf-8");
			PrintWriter writer = response.getWriter();
			JSONObject o = new JSONObject();
			o.put("status", "success");
			o.put("object", jsonObj);
			writer.write(o.toString());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

	}
发布了380 篇原创文章 · 获赞 6 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/spencer_tseng/article/details/102927954