Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I had a similar question yesterday - cud not resolve the issue

I am uploading a form with file and other inputs and all that is working fine. But the problem is that it is loading a new page i.e

www.mywebsite.com/controller/function. 

This is my code

<html>
<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script> 

<script type="text/javascript">
    $(document).ready(function() {
        var options = { 
            clearForm: true,
            resetForm: true
        };
        // bind 'myForm' and provide a simple callback function 
        $('#myForm').ajaxForm(function() { 
            //alert("Thank you for your comment!"); 

        }); 
        $('#myForm').ajaxForm(options);

    }); 
</script> 

</head>

<body>
<form id="myForm" name="myForm" action="/main/comment" method="post"         enctype="multipart/form-data"> 
    <input type="text" name="name" />
    <br /> 
    <textarea name="comment"></textarea> 
    <br />
    <input type="file" value="Share a Pic" name="file" id="file" />
    <br />
    <input type="submit" value="Submit Comment" /> 
</form>
</body>

I removed "main/comment" from my action and added url in var option part :-

var options = { 
            url: "<?php echo site_url().'/main/comment' ?>",
            clearForm: true,
            resetForm: true
        };

but even this does not seem to work. Please help Thanks

share|improve this question
Just a tip, you can use site_url and base_url this way <?php echo site_url('main/comment') ?> – Fabio Antunes Feb 27 at 21:01

1 Answer

If you follow the example shown here

I think you need to do this:

function successFunction(){
    alert('Thank you');
}
$(document).ready(function() {
        var options = { 
            clearForm: true,
            resetForm: true,
            success: successFunction
        };
        $('#myForm').ajaxForm(options);
});
share|improve this answer
this is not working – Stacy J Feb 28 at 9:26
@StacyJ Are you getting any errors in your javascript console? Do you have a live demo of this so I can see what's going on? – teewuane Mar 4 at 19:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.