【问题标题】:Couldnt upload file in Jquery Dialog using AJAX. Help !无法使用 AJAX 在 Jquery 对话框中上传文件。帮助 !
【发布时间】:2011-09-29 11:01:39
【问题描述】:

我正在使用 Zend 框架。 这是 index.phtml :

    <div id="edit-add-form" title="Insert">
    <form id="main-form" name="main-form" action="" method="post" enctype="multipart/form-data">

    </form>
    </div>
<a onclick="openAddPopup()">Open Popup</a>

我使用 ajax 从 addForm.phtml 将内容加载到模态对话框(edit-add-form div 元素):

openAddPopup = function(){
    $.ajax({
        type: "POST",
        url: '<?php echo $this->baseUrl()?>/core/database/landmark',
        data: "&act=insert",
        success: function(result,status,xResponse) {
        $("#main-form").html(result);
            $("#edit-add-form").dialog({
                autoOpen: true,
                title: 'Insert Data',
                width: $(window).width()-20,
                height: $(window).height()-20,
                resizeable: false,
                buttons: {
                            'Insert' : function() {
                                validateLForm();    
                            }
                            ,
                            Cancel: function() {
                                resetAllField();    
                                $(this).dialog('close');
                            }
                }

            });
        }
      });

}

这里是 addForm.phtml :

<input type="text" id="l_name" name="l_name">
<input type="file" id="l_image" name="l_image">
<input type="submit" name="upload" id="upload" value="Upload Image">

但是当我点击提交按钮时,只发布了文本输入,但文件输入没有。很奇怪吧?

非常需要你的帮助。 请注意。

【问题讨论】:

    标签: jquery ajax file upload dialog


    【解决方案1】:

    您缺少success 处理程序。你应该这样做:

    openAddPopup = function(){
        $.ajax({
            type: "POST",
            url: '<?php echo $this->baseUrl()?>/core/database/landmark',
            data: "&act=insert",
            success: function(result){ //This line!!!
                $("#main-form").html(result);
                $("#edit-add-form").dialog({
                    autoOpen: true,
                    title: 'Insert Data',
                    width: $(window).width()-20,
                    height: $(window).height()-20,
                    resizeable: false,
                    buttons: {
                                'Insert' : function() {
                                    validateLForm();    
                                }
                                ,
                                Cancel: function() {
                                    resetAllField();    
                                    $(this).dialog('close');
                                }
                    }
    
                });
    
            } //This line also!
         });
    
    }
    

    建议:使用 firefox 的 firebug Net 面板查看您的文件是否真的在上传

    希望这会有所帮助。干杯

    【讨论】:

    • 对不起,这是我的打字错误。我已经更新了我的帖子。仍然需要帮助。
    • 终于知道通过ajax上传文件是不可能的。使用 iFrame 是众多解决方案之一。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    相关资源
    最近更新 更多