0

我将使用jquery表单插件上传文件,关于响应数据为json时$.ajaxForm进程超时现象的问题。

服务端处理没有问题,只要用firebug看到json形式,就会以shape形式返回响应数据。但是,我认为 $.ajaxForm 无法获取数据。此后,它是已处理代码的一部分。

    代码
    $('#upload').ajaxForm({
    缓存:假,
    数据类型:'json',
    类型:'POST',
    错误:函数(xhr,状态,错误){
        alert('发生错误。状态:' + 状态
            + ' --状态文本:' + 错误
            + ' --错误结果:' + xhr.statusText);
    },
    超时:1000,
    数据类型:'json',
    数据:{“路径”:“路径”,“类型”:“类型”},
    完成:函数(){
        警报(“完成”);
    },
    成功:功能(数据){
        警报(“成功”);
    },
    });
    
    响应
    (萤火虫)

header Connection close Content-Length 155 Content-Type application/json; charset=utf-8 Status 200 data json {"type":"json","message":"complete process"} <i>(A browser)</i> ①download json data ②alert('error occured. Status:timeout --Status Text:timeout --Error Result:n/a') ③alert('complete') </pre>

当dataType为html时,可以处理成功。而且,当它是$.ajax 时,json 就成功了。有解决方案吗?它适当地问。

4

1 回答 1

0

try setting up the contentType like

   $('#upload').ajaxForm({
    cache: false,
    dataType: 'json',
    contentType:"application/json; charset=utf-8",
    type: 'POST',
    error: function(xhr ,status ,error ) {
        alert('error occured. Status:' + status
            + ' --Status Text:' + error
            + ' --Error Result:' + xhr.statusText); 
    },
    timeout: 1000,      
    data:{ 'path':'path' , 'type':'type' },
    complete: function(){
        alert('complete');
    },
    success:function(data){
        alert('success');
    },
    });
于 2011-09-02T06:38:48.617 回答