0

I am using ajaxupload for uploading and using jQuery 1.7.2. I got an error like this

TypeError: jQuery.createUploadForm is not a function
[Break On This Error]   

... jQuery.createUploadForm(id, s.fileElementId, (typeof(s.data)=='undefined'?false... 

my code is

function ajaxFileUpload()
    {
        jQuery.ajaxFileUpload
        (
            {
                url:'<?php echo $currenturl.&fileupload=enable;?>',
                secureuri:false,
                fileElementId:'fileToUpload',
                dataType: 'json',
                success: function (data, status)
                {
                    if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                            alert(data.error);
                        }else
                        {
                            alert(data.msg);
                        }
                    }
                }
            }
        )

        return false;

    }   

and the html is

<div class="upload-button"><input type="button" value="upload" id="upload-btn" onclick="return ajaxFileUpload();"/></div>

Please help me to solve this. Thanks in advance.

jackyesind
  • 3,343
  • 14
  • 47
  • 74

3 Answers3

1

The is not a function error can be caused by several things... most common are:

  • Path to plugin file is incorrect or not included in page at all. Easy to check in browser console that it is being loaded as a page resource
  • Order of scripts loading is incorrect. Plugin must load before you try to use it
  • jQuery.js not loading before all plugins and dependent code

EDIT: Another really common issue, especially on wordpress sites, is loading extra versions of jQuery after some plugins have loaded. If jQuery is loaded a second time after prior plugins load, it wipes them out

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • thanks for your there is 2 jquery.js files are included after removing one i got like this TypeError: jQuery.handleError is not a function [Break On This Error] jQuery.handleError(s, xml, status, e); – jackyesind Oct 27 '12 at 13:02
  • jQuery must load prior to any plugins, problem is likely just ordering the script tags – charlietfl Oct 27 '12 at 13:20
0

Make sure you have included jquery.js before the plugin js file.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="/js/myplugin.js"></script>

Also, avoid using the antiquated on* attributes in HTML. As you're already using jQuery in your function, you can simply attach a click handler to the element to run the function like this:

$(function() {
    $("#upload-btn").click(ajaxFileUpload);
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
0

You need to put your code into $(document).ready(function(){...}); event

Lukas1
  • 582
  • 1
  • 5
  • 28
  • `$(document).ready` has no bearing on a function not available – charlietfl Oct 27 '12 at 12:45
  • The idea is, maybe he needs to do some initialization code before using the click event and that code doesn't work because is not initialized in document ready event. But I admit, I don't know how the plugin works – Lukas1 Oct 27 '12 at 12:47