2011-09-30 22:02
浏览 53


I have been trying for the last couple of days to serialize a form in jquery and pass it to php. For some reason it just doesn't work... Question, What steps do you take to serialize a form in Jquery... I get the id of the form pass it into $('#fomrID').serialize()...

And it still doesn't work. When I debugg with firebug All I get is an empty string... Do you use the name or the Id of the form. Do you use e.disableDefalut or whatever that is? I can't figure out why I can't serialize my form please help

    alert("Boy I hate PHP");
    var formElement = $('#profilepicinput').attr('value');
    dataString = $("#registerpt3").serialize();
            type: "POST",
            url: "register3.php",
            data: dataString, //"profilePic="+formElement,
            success: function(data){
                alert( "Data Saved: " + data );
                    type: "POST",
                    url: "retrievePic.php", 
                    data: "",                   
                    success: function(data){
                        var image = new Image();
                            console.log("we have uploaded this image");
                        }).attr('src', 'images/');
                    error: function(msg){
                alert("" + msg);

    <form  id="registerpt3" name="registerpt3" enctype="multipart/form-data" action="register3.php" onSubmit="" method="post">
<input name="profilepicinput" type="file" id="profilepicbutton"  />
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douwei1950 2011-09-30 22:32

    According to

    For a form element's value to be included in the serialized string, the element must have a name attribute. Values from checkboxes and radio buttons (inputs of type "radio" or "checkbox") are included only if they are checked. Data from file select elements is not serialized.

    Also, simply calling serialize won't actually upload the picture for you. If you want to do an asynchronous picture upload (or any file for that matter) I'd suggest looking into something like Uploadify:

    解决 无用
    打赏 举报

相关推荐 更多相似问题