阿贾克斯表现不同在Firefox [英] Ajax behaving differently on Firefox

查看:159
本文介绍了阿贾克斯表现不同在Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上尝试检查的文件下载的进度。要做到这一点,我多次投票的PHP文件(progress_sess.php),这是呼应会话值处理下载(export.php)在文件中被改变。所以,有一个Ajax请求export.php和多个AJAX请求progress_sess.php。这样一来,我能够显示的阶段,目前文件下载脚本研究。 所有正在抓紧做好铬。 这是从请求清楚,你可以在这里看到的图像: - 铬请求

I am basically trying to check the progress of a file download. To do this, I am repeatedly polling a php file(progress_sess.php) which is echoing the session value being changed in the file handling the download (export.php). So there is one ajax request to export.php and multiple ajax requests to progress_sess.php. This way I am able to display the phase that the file download script is currently in. All is working out well in chromium. which is clear from the requests, you can see the image here: - Chromium Requests.

在Firefox中但引发此错误: -

In firefox However this error is thrown: -

JSON.parse: unexpected end of data at line 1 column 1 of the JSON data

您可以看到该请求的位置: - 火狐请求 当我回响在Firefox中xhr.responseText,它给本: -

You can see the request here: - Firefox Requests When I echo the xhr.responseText in Firefox, it gives this: -

""

这可能是因为在铬,你可以在图片中看到,该请求是应用程序/ JSON,如progress_sess.php头中指定,而在Firefox中的第一个请求是一些莫名其妙的原因text / plain的?因此,我不明白为什么Firefox是得到一个text / plain的响应头。

This is possibly because in Chromium as you can see in the image, the requests are application/json, as specified in the progress_sess.php header, whereas in firefox the first request is for some inexplicable reason text/plain?! So i do not understand why firefox is getting a text/plain response header.

您可以看到progress_sess.php: -

You can see progress_sess.php: -

<?php
    session_id($_COOKIE['phpMyAdmin']);
    session_start();
    header("Content-Type: application/json");
    $result = $_SESSION['export_progress'];
    if ($result==null) 
    {
        $result = '';
    }
    $arr = array(progress_result=>$result, source=>'progress_sess.php');
    echo json_encode($arr);
?>

因此​​,基本上是不可能的,有什么问题我的JSON。所以我想我的问题是,为什么它扔JSON解析错误,当我已明确指定了一个标题?难道是text / plain的请求头,因为,或由于Firefox和铬之间的一些Ajax的差异。

So basically it is impossible that there is something wrong with my json. So i guess my question is, why is it throwing json parse error when I have explicitly specified a header? is it because of the text/plain request header, or due to some ajax differences between firefox and chromium.

推荐答案

看起来像你的反应是不是一个有效的JSON字符串。的https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

Seems like your response is not a valid json-string. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse

这篇关于阿贾克斯表现不同在Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆