Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2009, 02:54 PM   PM User | #1
mumia55
New to the CF scene

 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
mumia55 is an unknown quantity at this point
Ajax xmlhttp request problem

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.

downloadfile.php

$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."\"");

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

and then my ajax script

response.js

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;

}
}
xmlHttp.open("GET",pagina,true);
xmlHttp.send(null);
}

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

thanks already! hope someone understand my needs :P
mumia55 is offline   Reply With Quote
Old 02-19-2009, 05:21 AM   PM User | #2
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
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.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 02-20-2009, 01:02 PM   PM User | #3
mumia55
New to the CF scene

 
Join Date: Feb 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
mumia55 is an unknown quantity at this point
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?
mumia55 is offline   Reply With Quote
Old 02-26-2009, 09:17 PM   PM User | #4
Crazy@pple
New to the CF scene

 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Crazy@pple is an unknown quantity at this point
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
@pple
Crazy@pple is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:00 PM.


Advertisement
Log in to turn off these ads.