开发者

Couldnt upload file in Jquery Dialog using AJAX. Help !

开发者 https://www.devze.com 2023-03-18 03:27 出处:网络
Im using Zend Framework. Here\'s index.phtml : <div id=\"edit-add-form\" title=\"Insert\"> <form id=\"main-form\" name=\"main-form\" action=\"\" method=\"post\" enctype=\"multipart/form-dat

Im using Zend Framework. Here's 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>

I use ajax to load content to modal dialog (edit-add-form div element) from addForm.phtml:

openAddPopup = function(){
    $.ajax({
        type: "POST",
        url: '<?php echo $this->baseUrl()?>/core/database/landmark',
        data: "&act=insert",
        succe开发者_StackOverflow中文版ss: 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');
                            }
                }

            });
        }
      });

}

Here's 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">

But when I hit the submit button, just only the text input posted, but the file input didnt. It's weird huh?

Need your help so much. Regard.


You're missing the success handler. You should do:

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!
     });

}

ADVICE: Use firefox's firebug Net panel to see if your file is really uploading

Hope this helps. Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消