解决iframe参数过长无法加载问题小记

解决iframe参数过长无法加载问题小记项目中用到了iframe,传参的时候使用的src属性,默认采用的get方式,此种方式在参数较长的时候就会报错(404无法找到资源),为了解决这种情况,改为采用post方式提交。解决方法:结合form表单,利用表单的post请求方式达到目的。实现方式 增加一个form表单的标签,method设置为post,target设置一个标识,假如target=”target1” 在iframe设置na…

大家好,又见面了,我是你们的朋友全栈君。

项目中用到了iframe,传参的时候使用的src属性,默认采用的get方式,此种方式在参数较长的时候就会报错(404无法找到资源),为了解决这种情况,改为采用post方式提交。解决方法:结合form表单,利用表单的post请求方式达到目的。

实现方式 
增加一个form表单的标签,method设置为post,target设置一个标识,假如target=”target1” 
在iframe设置name属性,name需要与target一致 name = “target1”

发送请求时通过发送form submit请求来使用post方式
以下代码用于定义iframe和相关form表单。

<form id="form1" action="" target="target1" method="post">
        <input name="Year" type="hidden" value="" />
        <input name="CommentUnitCode" type="hidden" value="" />
        <input name="CommentUnitType" type="hidden" value="" />
        <input name="dataType" type="hidden" value="" />
</form>
<iframe id="iframe1" name="target1"  src="" frameborder="0"></iframe>

以下代码用于定义form表单的提交对应的action方法和参数,这样就以post方式将参数传至后台,不必再担心参数过长的问题。 

var frame1 = document.getElementById('iframe1');
var url1 = "/DataDisplay/ShowRangeDataPage";
$('#form1 input[name=Year]').val(year);
$('#form1 input[name=CommentUnitCode]').val(CommentUnitCode);
$('#form1 input[name=CommentUnitType]').val(CommentUnitType);
$('#form1 input[name=dataType]').val(dataparams.dataType);
$('#form1').attr('action', url1);
$('#form1').submit();

表单提交后,在后台获取并保存参数值。

[HttpPost]
public ActionResult ShowRangeDataPage(ReportDataListRequest request)
{
	ViewBag.Year = request.Year;
	ViewBag.CommentElementValue = request.CommentElementValue;
	ViewBag.CommentUnitValue = request.CommentUnitValue;
	ViewBag.CommentUnitCode = request.CommentUnitCode;
	ViewBag.CommentUnitType = request.CommentUnitType;
	ViewBag.dataType = request.dataType;
	return View();
}     

前端ShowRangeDataPage页面调用post传的参数。

$.ajax({
		url: postUrl,
		type: 'post',
		dataType: 'json',
		data: {
			Year: Year,
			CommentUnitCode: '@ViewBag.CommentUnitCode',
			CommentUnitType: '@ViewBag.CommentUnitType',
			dataType: '@ViewBag.dataType'
		},
		success: function (result) {
			var data = eval(result.PieDataList);  
			data.sort(function (a, b) {
				return b.value - a.value;
			});
			clickProvice(data);
		},
		error:function (message) {
			console.log(message);
		}
});        

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/157969.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 年中总结[通俗易懂]

    年中总结[通俗易懂]年中总结

    2022年4月25日
    47
  • #ZipLib可以用于闭源软件

    #ZipLib可以用于闭源软件一直对各开源协议理解得不够透彻,对#ZipLib说的这段话:[quote]helibraryisreleasedundertheGPLwiththefollowingexception:Linkingthislibrarystaticallyordynamicallywithothermodulesismakingacombin…

    2022年7月26日
    3
  • [LeetCode]Find All Anagrams in a String

    [LeetCode]Find All Anagrams in a String

    2022年2月22日
    39
  • 随机抽奖小程序_在线随机抽号小程序

    随机抽奖小程序_在线随机抽号小程序本实例使用随机数字生成5位抽奖号码,并显示在窗体的5个文本框中。当用户单击"开始"按钮时,将启动一个线程对象为5个文本框生成随机数字。单击"抽奖"按钮时,线程对

    2022年8月2日
    2
  • SMO算法笔记及个人理解

    SMO算法笔记及个人理解SMO算法介绍SMO算法是一种启发式算法,其基本思路是:如果所有变量的解都满足此优化问题的KKT条件,那么这个最优化问题的解就得到了。(KKT条件是该最优化问题的充分必要条件)。否则,选择两个变量,固定其他变量针对这两个变量构建一个二次规划问题。特点:将原始的二次规划问题分解为只含有两个变量的二次规划子问题,对子问题不断求解,使得所有的变量满足KKT条件包含两部分:1、求解两个变量二次规划的解析方法2、选择变量的启发式方法(1)第1个变量的选择:确定在当前的分类器中,违反K.

    2022年6月22日
    33
  • matlab学习五,二元函数绘图方法

    matlab学习五,二元函数绘图方法plot3()绘制空间曲线%plot3(x,y,z,S)x,y,z为坐标,S为线型%绘制三维螺旋线x=cos(t)y=sin(t)z=tt=0:0.1:10*pi;x=cos(t);y=sin(t);z=t;plot3(x,y,z,’-r’);xlabel(‘x’);ylabel(‘y’);zlabel(‘z’);title(‘三维螺旋线’);2.绘制空间曲面绘制空间曲面的步骤为:绘制平面网格,计算网格上的函数值,绘制网面首先是绘制平面网格[X,Y]=m.

    2022年9月7日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号