View Full Version : Ajax xmlhttp request problem

02-18-2009, 02:54 PM
I'm having a curious problem, at least it's curious for me.. that when a start a download on my website, ajax functions stop working, only after the donwload stops, the functions work.
I'm going to show some parts of my code.


$fileType = $_GET['tipo'];
$fileSize = $_GET['tamanho'];
$fileContent = $b;
$fileName = $_GET['nome'];

// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache

header("Content-Description: File Transfer");
header("Content-type: $fileType");
header("Content-Length: ".filesize($fileSize));
header("Content-Disposition: attachment; filename=\"".$fileName."\"");

//for files bigger than 100megabytes
$fp = fopen($fileContent, "r");
while (!feof($fp)){
echo fread($fp, 65536);
flush(); // this is essential for large downloads

and then my ajax script


function ajaxAbre(pagina,id){
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
catch (e){
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
catch (e) {
alert("Seu navegador não suporta AJAX. Atualize-o em www.getfirefox.com");
return false;

xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState == 1) {
document.getElementById(id).innerHTML = "Carregando...<img src='./images/loading.gif'></img>";
if(xmlHttp.readyState == 4) {
document.getElementById(id).innerHTML = xmlHttp.responseText;


ajax code in my website works to change content in certain divs

thanks already! hope someone understand my needs :P

02-19-2009, 05:21 AM
What browser is it happening in?

With Internet Explorer, it is limited to two open connections to a domain. The download will clog the one connection leaving the other one open. When the download completes you have two connections.

So you should try using a sub domain/ CName for your download.


02-20-2009, 01:02 PM
I'm testing on Safari, Mozilla and Opera. They all behave the same, let me waiting for the download to finish, then ajax code works. And i'm sorry , can you explain with an example what you said before?

02-26-2009, 09:17 PM
Hey if you haven't already solved your problem I may be able to help. I've had problems with Ajax for months with it working in some places and not others so I tried to find a good javascript library to standardise how I use. I would recommend you either use a javascript library such as YUI or jQuery or use a javascript class like the one on this site www.dev-explorer.com/articles/ajax-request-class. I personally prefer to use straight javascript as opposed to frameworks but its up to you.

Hope this helps

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum