日期:2014-05-16  浏览次数:20783 次

ajax怎么传递大量复杂的数据到后台
jsp:
<c:forEach var="s" items="${news.newsP.list}" varStatus="i" >
<a href="javascript:void(0);"  onclick="createNewsHtml('${contextPath}/news/createHtml.do','${s.title}','${s.content}','<u:datetime date="${s.createdate}"  pattern="yyyy-MM-dd " invain="" />');return false;" >生成HTML</a>
</c:forEach>
----${s.content}---是新闻内容 差不多有1000个汉字 格式有用<p><h3>分段
<script type="text/javascript">
function createNewsHtml(url,title,content,date){
    
 url += "?title="+encodeURIComponent(encodeURIComponent(title))+"&content="+encodeURIComponent(encodeURIComponent(content))+"&date="+encodeURIComponent(encodeURIComponent(date));
    
     $.ajax( {
    global : false,
type : "get",
url :url+"&random="+Math.random(), 
async : false,
dataType: 'html',
timeout : 5000,
cache: false,

success : function(resp){
  alert("生成成功");
}
});
</script>
后台action:
String content=new String(URLDecoder.decode(StrutsEnv.getRequest().getParameter("content"), "UTF-8"));

问题就是后台取不到这么大量复杂的数据过来,如果是比较简单的数据比如:aaaaa就能正常取到,但是像上面1000左右的汉字就取不到了,上网查了下好像说ajax的get方式 用url传递数据有限制,好像用post方式可以
传递比较大的数据还有就是用xml格式传递。请高手教下怎么用,具体代码谢谢

------解决方案--------------------
没认真看,你参数加到url地址上了,这样其实还是get传参。。

    function createNewsHtml(url, title, content, date) {
        var data = "title=" + encodeURIComponent(encodeURIComponent(title)) + "&content=" + encodeURIComponent(encodeURIComponent(content)) + "&date=" + encodeURIComponent(encodeURIComponent(date));

        $.ajax({
            global: false,
            type: "POST",//////////////
            url: url,
            data: data, //////////////
            async: false,
            dataType: 'html',
            timeout: 5000,
            cache: false,

            success: function (resp) {
                alert("生成成功");
            }
        });
    }