dourong6054 2011-09-30 22:02
浏览 53
已采纳

在jquery中序列化表单并将其传递给php

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

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


    <form  id="registerpt3" name="registerpt3" enctype="multipart/form-data" action="register3.php" onSubmit="" method="post">
<input name="profilepicinput" type="file" id="profilepicbutton"  />
</form>
  • 写回答

1条回答 默认 最新

  • douwei1950 2011-09-30 22:32
    关注

    According to http://api.jquery.com/serialize

    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: http://www.uploadify.com/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 C# TCP服务端,客户端退出后,不断有数据进来
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?