Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    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
    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]

  • #3
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •