jquery表单插件json无法获取

发布于 2024-12-03 03:18:28 字数 1147 浏览 1 评论 0原文

我将使用jquery form插件上传文件,并询问当响应数据为json时$.ajaxForm处理超时的现象。

服务器端的处理很顺利,响应数据以firebug看到的json形式返回。 但是,我认为$.ajaxForm无法获取数据。此后,它是已处理代码的一部分。

    code
    $('#upload').ajaxForm({
    cache: false,
    dataType: 'json',
    type: 'POST',
    error: function(xhr ,status ,error ) {
        alert('error occured. Status:' + status
            + ' --Status Text:' + error
            + ' --Error Result:' + xhr.statusText); 
    },
    timeout: 1000,
    dataType:'json',
    data:{ 'path':'path' , 'type':'type' },
    complete: function(){
        alert('complete');
    },
    success:function(data){
        alert('success');
    },
    });
    
    response
    (firebug)

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就成功了。 有解决方案吗?它适当地问。

I will upload the file by using jquery form plugin, and question on the phenomenon of process of $.ajaxForm becoming timeout when the response data is json.

Processing by the servers end is done without trouble, and the response data is returned in the shape along as long as it sees with firebug the json form.
However, I think that $.ajaxForm cannot acquire data. Hereafter, it is a part of processed code.

    code
    $('#upload').ajaxForm({
    cache: false,
    dataType: 'json',
    type: 'POST',
    error: function(xhr ,status ,error ) {
        alert('error occured. Status:' + status
            + ' --Status Text:' + error
            + ' --Error Result:' + xhr.statusText); 
    },
    timeout: 1000,
    dataType:'json',
    data:{ 'path':'path' , 'type':'type' },
    complete: function(){
        alert('complete');
    },
    success:function(data){
        alert('success');
    },
    });
    
    response
    (firebug)

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>

When dataType was html, success was able to be processed.
Moreover, when it is $.ajax, json becomes success.
Are there a settlement plan?It asks suitably.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间☆小暴躁 2024-12-10 03:18:28

尝试设置 contentType

   $('#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');
    },
    });

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');
    },
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文