SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot phpguru's Avatar
    Join Date
    Sep 2005
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    don't submit form, but send POST data with AJAX

    here's my example

    PHP Code:
    <script>
    function 
    test(url) {
            
    xmlhttp.onreadystatechange TransResp;
        
    xmlhttp.open("POST",url,true);
        
    xmlhttp.setRequestHeader("Content-Type","multipart/form-data");
    xmlhttp.send(
            
    "image="+document.getElementById("image").value;
        );
        return 
    true;
    }
    </script>
    <input id="image" type="file">
    <inpyt type="button" value="upload" onClick="test('myurl')"> 
    and i want send this $_FILES data (PHP) though: multipart/form-data
    but it seems not ok.

  2. #2
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to read the data of the file, not it's file name. That should be impossible to do because some security reasons.

    You can try submitting a form to a hidden iframe (<iframe name="submitter" style="display: none" src="about:blank"></iframe>) and change the form's target to "submitter"



    And also, you used inpyt instead of input!


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
  •