简体   繁体   English

Ajax在Firefox上的行为有所不同

[英]Ajax behaving differently on Firefox

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). 为此,我反复轮询一个php文件(progress_sess.php),该文件正在回显处理下载文件(export.php)的会话值。 So there is one ajax request to export.php and multiple ajax requests to progress_sess.php. 因此,有一个针对ajax的export.php请求和多个针对ajax的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 . 从请求中可以清楚地看到,您可以在此处看到图像:- 铬请求

In firefox However this error is thrown: - 在firefox中,但是抛出此错误:-

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

You can see the request here: - Firefox Requests When I echo the xhr.responseText in Firefox, it gives this: - 您可以在此处看到请求: -Firefox请求当我在Firefox中回显xhr.responseText时,它显示以下内容:-

""

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?! 这可能是因为在Chromium中(如您在图像中看到的那样),请求是application / json,如progress_sess.php标头中所指定,而在firefox中,第一个请求是出于某种无法解释的原因text / plain ?! So i do not understand why firefox is getting a text/plain response header. 所以我不明白为什么Firefox会得到一个文本/纯响应头。

You can see progress_sess.php: - 您可以看到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);
?>

So basically it is impossible that there is something wrong with my json. 所以基本上我的json不可能出问题。 So i guess my question is, why is it throwing json parse error when I have explicitly specified a header? 所以我想我的问题是,当我明确指定标头时,为什么会引发json解析错误? is it because of the text/plain request header, or due to some ajax differences between firefox and chromium. 是由于text / plain请求标头,还是由于firefox和chrome之间的一些ajax差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM