English 中文(简体)
jquery:我如何在jquery中编造文档类型输入
原标题:jquery: how do I serialize file type input in jquery

我想将文件上载到投入类型档案中,但当我把表格编成分类时,我只拿到了投入类型文本,而其他人则不是档案——我如何这样做? 难道这种 j笑没有实现吗?

The html/php:

<form action="<?php echo HTTP_ROOT.INC_LAYOUT;?>ask_add_xml.php" method="post" enctype="multipart/form-data" id="form_qna_ask">

        <div class="item-form">
            <h2><a href="#"><span>ASK</span></a></h2>
            <label id="ask_title_label">
            <input type="text" name="ask_title" id="ask_title" value="" title="TYPE IN A TITLE"/>
            </label>
        </div>

        <div class="item-form">
            <h2><a href="#"><span>EMAIL</span></a></h2>
            <label id="ask_email_label">
            <input type="text" name="ask_email" id="ask_email" value="" title="TYPE IN YOUR EMAIL"/>
            </label>
        </div>

        <div class="item-form">
            <label id="ask_content_label">
                <textarea name="ask_content" id="content_mce" title="CONTENT"></textarea>
            </label>
        </div>

        <div class="item-form">
            <div class="left">
                <label>
                <img src="views/www/styles/images/global/button-add-images-q-n-a.gif" alt="add images" style="float:left;"/> 
                <h2 id="add_images_label"><a href="#"><span>Add Images</span></a></h2>
                </label>
            </div>

            <div class="right">
                <div class="processing"></div>
                <input type="submit" name="cancel" value="CANCEL"/>
                <input type="submit" name="submit" value="SUBMIT"/>
            </div>
        </div>


        <div class="item-form" style="border:1px solid #bbbbbb; padding:10px 10px 20px 15px; background-color:#ffffff;">
            <p>Add images: this allows you to attach pictures to your question. Only 2 pictures at 2MB each are allowed to upload.</p>
            <input type="file" name="image[]"/>
            <input type="file" name="image[]" />
        </div>

    </form>

这是 j,

this.postForm_ask = function(){
$("#form_qna_ask").submit(function(){
    $( #popup_result ).remove();
    var path = $(this).attr( action );
    var processing = $( #q-n-a .processing );
    processing
        .css({
            margin:"0px 0px 0px -80px",
            position:"absolute",
            visibility:"visible"
            });

    processing.html( <div><p><img src=" +http_root+img_global+ loader-2b.gif"/> loading</p></div> );
    $.post(path, $("#form_qna_ask").serialize(),function(xml){
            alert($("#form_qna_ask").serialize());
            processing
                .css({
                    visibility:"hidden"
                    });
            processAsk(xml);
        });
    return false;
    });
}

many thanks, Lau

最佳回答

页: 1 只是用下面的ug子来分类!

http://malsup.com/jquery/form/#ap-started

最后法典

this.postForm_ask = function(){

 $( #form_qna_ask ).submit(function() { 
  var processing = $( #q-n-a .processing );
  processing
   .css({
    margin:"0px 0px 0px -80px",
    position:"absolute",
    visibility:"visible"
    });
  processing.html( <div><p><img src=" +http_root+img_global+ loader-2b.gif"/> loading</p></div> );
  $(this).ajaxSubmit({ 
   target:  #output ,
   // dataType identifies the expected content type of the server response 
   dataType:   xml , 

   // success identifies the function to invoke when the server response 
   // has been received 
   success: processXML_ask 
  }); 
        return false; 
 });

}

this.processXML_ask = function(xml){ //  ==  function addMessages(xml) {  

 var processing = $( #q-n-a .processing );
 processing.css({
     visibility:"hidden"
     });

 $(document.body).append("<div id="popup_result" class="popup"></div>");
 var target = $( #popup_result );
 var scrollTop = $(window).scrollTop();
 var scrollLeft = $(window).scrollLeft();
 var width = 400;
 var top = 200;
 var marginLeft = "-"+ ((scrollLeft + width)/2);
 target
  .css({
   top:(scrollTop + top) + "px", 
   left:"50%",
   marginLeft:marginLeft + "px",
   width:width + "px",
   zIndex:"11",
   display:"none"
   });

 target.load(http_root+inc_layout+"result.php", {}, function(){
 $("error", xml).each(function(){
  var elementid = $(this).attr( elementid );
  var message = $(this).attr( message );
  //alert(elementid);
  $("#"+elementid+"_label").addClass( error-qna );
  $(".result").append("<img src= "+http_root+img_global+"attention.png  /> <b>" + message + "</b> <br />");
   target.fadeIn( slow , function(){ 
    closePopup(target);
    //$( form *[title] ).inputHint();
   }); 
  });
 $("result", xml).each(function(){
  var message = $(this).attr( message );
  $(".result").append("<img src= "+http_root+img_global+"info.png  /> <b>" + message + "</b> <br />");
   target.fadeIn( slow , function(){ 
    closePopup(target);
    clearFormElements( form );
    $( .form *[title] ).inputHint();
    $( input:file ).MultiFile( reset );
   }); 
  }); 
 });
}
问题回答

当然,你想要让这一服务器发挥作用? 档案以双亲寄送,无法通过XHR任何途径寄送。

如果你想要即时立上载,就使用一机。





相关问题
Choosing the right subclass to instantiate programmatically

Ok, the context is some serialization / deserialization code that will parse a byte stream into an object representation that s easier to work with (and vice-versa). Here s a simplified example ...

WCF Problem Sending Object To Client

Background Converting from using .Net Remoting to WCF. Most of the methods on the WCF server are working fine, but ran into one that isn t working today. This is the service contract: [...

WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

deserialize the XML Document --- Need Help

I am using the below code snippet now to deserialize the XML document ... [WebMethod] public XmlDocument OrderDocument(XmlDocument xmlDoc) { XmlSerializer serializer = new XmlSerializer(typeof(...

How do I serialize a child class?

how do I include the serialized data from a child class where both impliment iserializeable? Class A Implements ISerializable dim _B as new B Class B Implements ISerializable ...

WCF: Serialize complex objects with read-only members

Looking for some guidance on a WCF service I’m prototyping. I have a WCF service hosted in IIS that will pass data to my clients. I have a separate shared assembly that contains all my business ...

Long/multiple SQL queries vs Serialization

I m trying to improve the performance of my web app where a page does a long query to pull data from different tables on a database. It pulls invoice data with multiple item lines, invoice status, and ...

热门标签