0

这是我的表格:

<form id="register" enctype="multipart/form-data">
    <input type="text" name="first_name" placeholder="First Name" id="first_name" />
    <input type="text" name="last_name" placeholder="Last Name" id="last_name" />        
    <input type="text" name="input_email" placeholder="Confirm your email"  id="input_email" class="loginEmail" />
    <input type="password" name="input_password" placeholder="Password" id="input_password" class="loginPassword" />
    <input type="password" name="repeat_password" placeholder="Repeat password" id="repeat_password" class="loginPassword" />
    <input type="file" name="image_file" id="image_file" />

    <div class="logControl">
        <div class="memory"></div>
        <input type="submit" name="submit" value="Register" class="buttonM bBlue" id="register_submit"/>
        <div class="clear"></div>
    </div>
    <p><h3>Or click <a href="login.html">here</a> to login</h3></p>
</form>

这是我进行的 jquery 调用:

     function WCFJSON() {
         $(".memory").html('<img src="images/elements/loaders/7s.gif" />');
         Data = new FormData($('form')[0]);
         $.ajax({
             type: 'POST', //GET or POST or PUT or DELETE verb
             url: "WCFService/Service.svc/Register", // Location of the service
             data: Data, //Data sent to server
             async:false,
             cache:false,
             contentType: false, // content type sent to server
             dataType: "json", //Expected data format from server
             processdata: false, //True or False
             success: function(msg) {//On Successfull service call
                 ...
             },
             error: ...// When Service call fails
         });
     }

     $(document).ready(function(){
         $("#register").submit(function(){              
            WCFJSON();
            return false;
        });
    });

现在,当我提交表单时,页面会使用 url 中的 get 元素刷新。但是如果我从表单中删除文件输入,jquery 工作正常。

4

0 回答 0