+ -
当前位置:首页 → 问答吧 → 内容过长ajax无刷新post无法提交问题

内容过长ajax无刷新post无法提交问题

时间:2010-10-18

来源:互联网

Java code
/**
* Djkk Ajax Class
* @ Author: iFiky , [email protected]
* @ Create date: 2008.07.13
* @ Update date: 2008.09.18
* @package Djkk.Com
*/

var Dj97_ajax = function(_obj){
    if (_obj){
        this.method = _obj.method;
        this.url = _obj.url;
        this.async = _obj.async;
        this.responseType = _obj.responseType;
    };
        
    this.create_xmlHttp = function(){
        var xmlHttp = false;
        if(window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
            if (xmlHttp.overrideMimeType) {
                xmlHttp.overrideMimeType('text/xml');
            }
        }else if (window.ActiveXObject){
            try{
                xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
            } catch (e) {
                try {
                    xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
                } catch (e) {}
            }
        }
        return xmlHttp;
    };
    this.send = function(_data){
        if ( undefined == this.method ) this.method = 'GET';
        if ( undefined == this.async ) this.async = true;
        if ( undefined == this.responseType ) this.responseType = 'text';
        if ( undefined == this.onReady ) this.onReady = function(_dj97_com){};
        _data = ( undefined == _data ) ? null : _data;

        if ( 'GET' == this.method.toUpperCase() ){
            this.url = this.url + '?' + _data;
            _data = null;
        };
        var obj = this.create_xmlHttp();
        
        obj.open (this.method, this.url, this.async);
        if ( 'POST' == this.method.toUpperCase() ){
            if (_data!=null) obj.setRequestHeader('Content-Length', _data.length);
            obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=gb2312');
        }else{
            obj.setRequestHeader('Content-Type', 'text/html;charset=gb2312');
        };
        var Me = this;
        obj.onreadystatechange = function(){
            if (obj.readyState==4){
                var result = '';
                if (obj.status==200){
                    if ( 'TEXT' == Me.responseType.toUpperCase() )
                        result = obj.responseText;
                    else if( 'XML' == Me.responseType.toUpperCase() )
                        result = obj.responseXml;
                    obj = null;
                }else{
                    alert("网络出现故障, 请刷新后重试!!"+obj.status);
                }
                Me.onReady(result);
            }
        };
        obj.send(_data);
    };
};


请问ajax无刷新提交时,post这个能发送多大的内容?
我提交的内容较少时。。可以成功提交。。

提交的内容比较多时。。就出错了。。

提示“网络出现故障,请刷新后重试!!122

作者: laizongyao   发布时间: 2010-10-18

简化代码 把不必要的代码可以写在Action中 比如编码过滤之类的 在页面中只写可以出现的正确结果的逻辑代码应该就可以了 把格式验证和回显可以写成一个JS文件 再在页面引用 可以提高代码重用率 节省时间

作者: yiyulanmo   发布时间: 2010-10-18

post在客户端理论上是没有限制的,只有你的服务器是否支持多大的数据量。

如asp默认的post大小为200k,超过200k就出错了,不过可以通过设置iis的配置文件来提高接收数据的大小

JScript code
else{//输出responseText看返回什么东东
                    alert("网络出现故障, 请刷新后重试!!"+obj.responseText);
                }

作者: showbo   发布时间: 2010-10-18

热门下载

更多