adib16
adib16

Reputation: 1697

send only on file in the form with ajax

I have a form with 10 input file type tag.I want to send only one of the file to the server with ajax.not problem in modern browser that support formData .my problem is in the olden browser that not support formData.i use this code for olden browser. html form

<form name="multiform" id="multiform" action="multi-form-submit.php" method="POST" enctype="multipart/form-data">
Image1 :<input type="file" name="photo1" /><br/>

image2 :
Image3 :

javascript code

function getDoc(frame) {
     var doc = null;

     // IE8 cascading access check
     try {
         if (frame.contentWindow) {
             doc = frame.contentWindow.document;
         }
     } catch(err) {
     }

     if (doc) { // successful getting content
         return doc;
     }

     try { // simply checking may throw in ie8 under ssl or mismatched protocol
         doc = frame.contentDocument ? frame.contentDocument : frame.document;
     } catch(err) {
         // last attempt
         doc = frame.document;
     }
     return doc;
 }
$("#multiform").submit(function(e)
{
    var formObj = $(this);
    //var formURL = formObj.attr("action");
        var formURL="multi-form-submit.php";
var  iframeId = "unique" + (new Date().getTime());

        //create an empty iframe
        var iframe = $('<iframe src="javascript:false;" name="'+iframeId+'" />');

        //hide it
        iframe.hide();

        //set form target to iframe
        formObj.attr("target",iframeId);
        //Add iframe to body
        iframe.appendTo("body");
        iframe.load(function(e)
        {
            var doc = getDoc(iframe[0]);
            var docRoot = doc.body ? doc.body : doc.documentElement;
            var data = docRoot.innerHTML;
            alert(data);

        });

multi-form-submit.php file :

<?php
 move_uploaded_file($_FILES["photo"]["tmp_name"],
      "upload/" . $_FILES["photo"]["name"]);

?>

when the user select photo1 and photo2 and photo3 and click on the submit i want to send only photo2 to server.how can I do that?

Upvotes: 0

Views: 184

Answers (1)

慵懒de土豆
慵懒de土豆

Reputation: 11

for olden browsers, iframe submit form would create gibberish when form contains Chinese, Japanese...

Upvotes: 1

Related Questions