SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Indonesia - Bali
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript technique for periodic request

    hello everyone i have a idea for making web app AJAX Based that need periodic request. i'am so sorry coz i'am not implementing this idea yet.

    my idea is making web app for uploading file with progress bar indicator. so., the file that i have to upload with iframe technique. and i will make one script again again that checking file on the server. so.., i / the script need to listening continuesly to the file on the server.

    how i can implement this periodic request ??

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You could use a setTimeout on the changescript function in the form
    Code:
    setTimeout(changescript("getCurrentFileSize.asp?file="+filename),milliseconds)
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Indonesia - Bali
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    woww... thank you for your help... i think it will be work

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Indonesia - Bali
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello everyone... i have tried to implementing my idea.. but it seems failed for the progress indicator job.

    that's all because the ajax based checker script can't get the $_FILES value i think coz that script not an action of the form element so can't catch value from $_FILES['myfilename']

    and i'am not found a way yet for getting filesize of uploaded file and current size of transferred file.

    i have two php file, for upload file and periodic checking to the server. but this script which used to checking file on server can't catch value $_FILES as i mentioned above

    this is my do_upload.php
    Code PHP:
    <?php
    move_uploaded_file($_FILES["sourcefile"]["tmp_name"],
    "uploaded_file/" . $_FILES["sourcefile"]["name"]);
    ?>
    check.php
    Code PHP:
    <?php
    //total besar data sebelum diupload
    $totalsize = $_FILES['sourcefile']['size']; /*  << --- this is i mean*/
     
    //besar data (potongan2 data yg udah nyampe server) terkini
    $current_size = filesize($_FILES['sourcefile']['tmp_name']);
    ?>

    this is ajax based for periodic checking
    Code JavaScript:
    /*
    Interface ajax - nye.. 
    */
    var par = window.parent.document;
     
    //Mbikin Object XMLHttpRequest biar cross browser
    function createRequestObject() {
    	var ro;
    	var browser = navigator.appName;
    	if(browser == "Microsoft Internet Explorer"){
    		ro = new ActiveXObject("Microsoft.XMLHTTP");
    	}else{
    		ro = new XMLHttpRequest();
    	}
    	return ro;
    }
    //akses objek pariwisata hee...
    var XMLHttpRequestObject = createRequestObject();
     
    //Fungsi ini mbuat check data yg dalam perjalanan dah nyampe
    //berapa 'orang'?? hehe....
    function getData(elemen_id)
    {
     
    	// hide old iframe
    	var iframes = par.getElementById('frame');
    	//var iframe = iframes[iframes.length - 1];
    	iframes.style.display = 'none';
     
    	//show progress material
    	par.getElementById("progressbar").style.display = "block";
    	par.getElementById("msg").style.display = "block";
     
    	//Do the job!
    setTimeout("sendRequest_and_handleResponse('check.php?sourcename=sourcefile',elemen_id)"
    ,2000);
    }
     
    function sendRequest_and_handleResponse(t_url,t_elemen_id)
    {
     
     
    	XMLHttpRequestObject.open("GET", t_url, true);
    	XMLHttpRequestObject.onreadystatechange = function ()
    	{
    	if (XMLHttpRequestObject.readyState == 4)
    	{
    		var txtDocument = XMLHttpRequestObject.responseText;
    		var optionsx = txtDocument.split('#');
     
    		//Ukur ukur...
    		var total_datasize = optionsx[0];
    		var ukuran_terkini = optionsx[1];
     
    		//mencari persentase size data
    		var persentase_data_terupload = total_datasize / ukuran_terkini * 100;
     
    		//klo dah dapet persentase data, maka kita akan ubah ukuran progress bar yg 
    		//kita visualisasikan dalam bentuk table
    		par.getElementById(t_elemen_id).width = persentase_data_terupload+"%";	
    	} else { alert('not complete loaded yet'); }
    	}
    	XMLHttpRequestObject.send(null);
    }

    and, i'am using iframe
    this is my index.html file which css stylesheet not i included
    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    </HEAD>
     
    <BODY>
    <div id="wrap_this">
    <iframe id="frame" name="datasource" src="upload_iface.html" frameborder="0"></iframe>
    <div id="progressbar" style="display:none;">
    <TABLE id="tableprogress" width="0%" bgcolor="green">
    	<TR>
    	<td width='100%' style="height: 20px">
    	</td>
    	</TR>
    </TABLE>
    </div>
    <h3 id="msg" style="display:none">Upload in progress</h3>
    </div>
     
    </BODY>
    </HTML>

    and this is my upload_iface.html
    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    <script language="JavaScript" src="check_interface.js" type="text/javascript"></script>
    <style type="text/css">
    body {
    background-color:#999999;
    }
    </style>
    </HEAD>
     
    <BODY>
    <form action="do_upload.php" method="POST" name="form_submitter" enctype="multipart/form-data" onSubmit="getData('tableprogress')">
    <h1>File Uploader with Progress Bar </h1>
    <label for="sourcefile">Choose your file</label>
    <input type="file" name="sourcefile"/><br />
    <input type="submit" name="submit_file" value="Upload!">
    </FORM>
    </BODY>
    </HTML>

    i don't know what to do next within this project. i'am not found a way yet and i think much of bug from my source code above.

    thx
    Last edited by linspirell; Aug 5, 2007 at 10:15. Reason: adding some code fixes

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    Indonesia - Bali
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anybody here understand my problem?? please help me

    thx

  6. #6
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I don't use ajax. Doesn't seem to be any point when using the changescript function.

    I s'pose the problem your having is the getting of the filename to send to the server so you can check its size. I don't think there's any way of checking the files total size until it's uploaded. Also, IE is the only browser that you can get the filename from the input box.
    Code:
    <input type="file" name="file_1" id="file_1">
    <input tpye="submit" onclick="changescript('getFileSize.asp?file='+document.getElementById('file_1').value">
    That will only work in IE.

    With other browsers you could check the file that is in the temp upload directory, but I don't know how many files could be in the temp folder before they are moved, especially on a busy server.

    Sorry I can't help any further, not without testing, and at the moment I am quite busy.
    Last edited by Markdidj; Aug 7, 2007 at 01:12.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Bookmarks

Posting Permissions

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