jQuery Handler error is not a function

蓝咒 提交于 2019-12-30 08:33:12

问题


I am using jquery ajax fileupload. the file is uploaded correctkly but i got error like

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

jQuery.handleError(s, xml, status, e); 

using jQuery version 1.7.2 and the code is

jQuery.ajaxFileUpload
        (
            {
                url:'<?php echo $currenturl.'&fileupload=enable';?>',
                secureuri:false,
                fileElementId:'fileToUpload',
                dataType: 'json',
                data:{'image_desc':image_desc,'gallery_id':curr_time_stamp},
                success: function (data, status)
                {   

                     if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                            alert(data.error);
                        }else
                        {
                            alert(data.msg);
                            showprofilepicture();
                        }
                    }
                }

            }
        ) 

the function showprofilepicture() also not excuted.


回答1:


The jQuery.handleError was removed after the jQuery version in 1.5 you need to write a custom error handler function to solve this like

jQuery.extend({
    handleError: function( s, xhr, status, e ) {
        // If a local callback was specified, fire it
        if ( s.error )
            s.error( xhr, status, e );
        // If we have some XML response text (e.g. from an AJAX call) then log it in the console
        else if(xhr.responseText)
            console.log(xhr.responseText);
    }
});

Refer from the blog. Thanks John Main for your information




回答2:


             if(typeof(data.error) != 'undefined')
            {
                if(data.error != '')
                {
                    alert(data.error);
                }else
                {
                    alert(data.msg);
                    showprofilepicture();
                }
            }

should be

jQuery.ajaxFileUpload({
            url:'<?php echo $currenturl."&fileupload=enable";?>',
            secureuri:false,
            fileElementId:'fileToUpload',
            dataType: 'json',
            data:{'image_desc':image_desc,'gallery_id':curr_time_stamp},
            success: function (data, status)
            {   

                 if(typeof(data.error) != 'undefined')
                {
                    if(data.error != '')
                    {
                        alert(data.error);
                    }
                }else
                    {
                        alert(data.msg);
                        showprofilepicture();
                    }
            }

        }
    ) 


来源:https://stackoverflow.com/questions/13107536/jquery-handler-error-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!