www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Request forces navigation from page (possibly a n00b question)

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    22

    resolved [RESOLVED] Request forces navigation from page (possibly a n00b question)

    Hi!
    I am trying to make a simple test AJAX script...

    loadFile.html:
    Code:
    <script>
    function performRequest()
    {
    	var req = new XMLHttpRequest();
    	req.open("POST", "./bounce.php", false);
    	req.onload = function()
    	{
    		alert(req.responseXML);
    	};
    	req.send(new FormData(document.getElementById("uploadForm")));
    }
    </script>
    
    <body>
    	<form	enctype= 'multipart/form-data' method= 'POST' name= 'uploadForm' id= 'uploadForm' action= ''>
    		<input type= 'hidden' name= 'mode' id= 'mode' value= 'upload'>
    		<input type= 'file' name= 'sourcefile' id= 'sourcefile' required>
    		<input type= 'button' value= 'Upload' onClick= 'performRequest()'>
    	</form>
    </body>
    bounce.php:
    PHP Code:
    <?php
        
    if ($_POST["mode"] == "upload")
            if (
    is_uploaded_file($_FILES["sourcefile"]["tmp_name"]))
                @
    readfile($_FILES["sourcefile"]["tmp_name"]) or exit("Dang!");
    ?>
    I want it to alert the contents of the selected file when I click "Upload," but for some reason it navigates me to "bounce.php" and displays the content there!
    I thought AJAX was supposed to be about not leaving the page...
    What am I doing wrong?

  2. #2
    Join Date
    Jul 2010
    Posts
    22
    bump

  3. #3
    Join Date
    Jul 2010
    Posts
    22
    Forget it, it was a file mixup. Everything is working now.

  4. #4
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    Glad you got it figured out.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles