jquery form not working as expected. ajaxForm is not a function
Asked Answered
T

4

17

I am trying to use jquery form but it sais in the concole ajaxForm is not a function. The jquery.form.js is properly included and the code is in a document ready function...

This is the script:

$("#apply-form").ajaxForm({

                beforeSend: function()
                {
                    $("#progress").show();
                    //clear everything
                    $("#bar").width('0%');
                    $("#message").html("");
                    $("#percent").html("0%");
                },
                uploadProgress: function(event, position, total, percentComplete)
                {
                    $("#bar").width(percentComplete+'%');
                    $("#percent").html(percentComplete+'%');

                },
                success: function()
                {
                    $("#bar").width('100%');
                    $("#percent").html('100%');

                },
                complete: function(response)
                {
                    $("#message").html("<font color='green'>"+response.responseText+"</font>");
                },
                error: function()
                {
                    $("#message").html("<font color='red'> ERROR: unable to upload files</font>");

                }
            });

And here is the HTML form

<form id="apply-form" enctype="multipart/form-data" method="post" action="">


    <table>
                <tr><td>CV:</td>
                    <td>
                        <input type="file" name="cover">
                    </td>
                </tr>
                <tr><td>Cover Letter:</td>
                    <td>
                        <input type="file" name="curriculum">
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div id="progress">
                            <div id="bar"></div>
                            <div id="percent">0%</div >
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <div id="message"></div>
                    </td>
                </tr>
            </table>
        </form>

i am making the site in codeigniter and i have a header template that is included o every page. and in the head section i am including all my scripts in this order:

<script src="/jobs/public/js/jquery.js"></script>
<script src="/jobs/public/js/jquery.form.js"></script>
<script src="/jobs/public/js/javascript.js"></script>
<link href="/jobs/public/js/jquery-ui-1.10.3.custom/css/custom-theme/jquery-ui-1.10.3.custom.css" rel="stylesheet">
<script src="/jobs/public/js/jquery-ui-1.10.3.custom/js/jquery-1.9.1.js"></script>
<script src="/jobs/public/js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.js"></script>

I am also using jQuery UI. Could that be the problem?

Tortuosity answered 4/9, 2013 at 12:47 Comment(9)
Is jQuery itself also loaded properly? Can you make a jsfiddle with your HTML also?Ephemeron
yep. and it is loaded before jquery formTortuosity
any other error in your consoleGeorg
Does $().ajaxForm in your browser's inspector return the `ajaxForm function?Navel
no any other errors. just this oneTortuosity
$().ajaxForm returns undefined...Tortuosity
ajaxForm library might not be loaded when document gets ready, you can find this in chromes network tab or see the inspector's console.Chau
Could you show us where and how you load the scripts?Loads
in firebug at the script section the jquery.form.js appears as includedTortuosity
Q
27

You are loading jQuery twice. The second loading of jQuery overrides the first and clobbers any plugins.

<script src="/jobs/public/js/jquery.js"></script>
<script src="/jobs/public/js/jquery.form.js"></script>
...
<script src="/jobs/public/js/jquery-ui-1.10.3.custom/js/jquery-1.9.1.js"></script>

It is this second jquery-1.9.1 that is not getting .ajaxForm. Use one or the other.

Add the form jquery to the bottom of the scripts

Quotha answered 4/9, 2013 at 13:18 Comment(2)
thanks man. I didn't realise i included it twice...the second one was from jQuery UI :)Tortuosity
you post just saved me a whole day wasted, double loading of jquery detected. thanksBreena
C
13

Use this and work is done

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js" integrity="sha384-qlmct0AOBiA2VPZkMY3+2WqkHtIQ9lSdAsAn5RUJD/3vA5MKDgSGcdmIv4ycVxyn" crossorigin="anonymous"></script>
Carloscarlota answered 6/4, 2015 at 14:20 Comment(1)
Does not work anymore. Use this instead: <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js" integrity="sha384-qlmct0AOBiA2VPZkMY3+2WqkHtIQ9lSdAsAn5RUJD/3vA5MKDgSGcdmIv4ycVxyn" crossorigin="anonymous"></script>Riles
S
3

i designed a good uploader just like this :

<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="jquery.form.js"></script>

and worked complete and used ajax just like this :

$('form').ajaxForm
    ({

    beforeSend: function() 
    {
    var percentVal = '20%';
    prog.css("width",percentVal);

    },
    uploadProgress: function(event, position, total, percentComplete) 
    {
    var percentVal = percentComplete + '%';

    prog.css("width",percentVal);
    darsad.html(percentVal + ' uploading .');
    //console.log(percentVal, position, total);
    },
    success: function() 
    {
    var percentVal = '100%';

    darsad.html(percentVal + ' uploaded success.');
    prog.css("width",percentVal);

    },
    complete: function(xhr) 
    {
    //status.html(xhr.responseText);
    darsad.html(percentVal + ' uploaded complete.');
    }

    }); 
Swale answered 15/10, 2013 at 23:11 Comment(0)
R
0

ajaxForm is not a function basically means, either the function does not exist or the function has problems somewhere.

I fixed this by sort back the plugin load/ path and js file. In my case, the function can't be called because the order is wrong.

Rowley answered 16/2, 2021 at 2:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.