Hello I try to upload a picture to my server using ajaxForm.
My problem is that the page is redirecting to the URL in the form action.
This is my ajax code:
$("#uploadPicture").html("<form action='actionFilters/TrainerActionFilter.php' method='post' enctype='multipart/form-data' id='pictureUpload'><input type='file' name='picture'/><input type='submit' name='pictureUpload' id='pictureUploadButton' value='Submit' />);
$('#pictureUpload').ajaxForm(function(data)
{
});
If I send to the same address normal ajax (not ajaxform) Im not having this problem.
Not 100% sure, but you can try using the beforeSubmit
function of ajaxForm
?
var ajaxFormOptions =
{
beforeSubmit: function()
{
alert("Your action before here");
}
};
$('#pictureUpload').ajaxForm(ajaxFormOptions);
If you want to catch the submit in a custom js function then add onSubmit="return false;"
to the form
$("#uploadPicture").html("<form action='actionFilters/TrainerActionFilter.php' onSubmit='return false;' method='post' enctype='multipart/form-data' id='pictureUpload'><input type='file' name='picture'/><input type='submit' name='pictureUpload' id='pictureUploadButton' value='Submit' />");
$('#pictureUpload').ajaxForm(function(data)
{
});