0

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",
        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');
                            }
                }

            });
        }
      });

}

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, it's my typo mistake. I've updated my post. Still need help.
Finally I know that it's impossible to upload a file via ajax. Using iFrame is one of many solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.