Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Tabs and Uploadify Object Expected

I am using uploadify plugin inside jquery tabs which works perfectly fine. Inside the uploadify once upload is completed i am sending email as such :

 $('#file_upload').uploadify({
                'fileTypeDesc': 'Image Files',
                'fileTypeExts': '*.gif; *.jpg',
                'swf': 'Scripts/Uploadify/uploadify.swf',
                'uploader': 'FileUploadHandler.ashx',
                'cancelImg': 'Scripts/Uploadify/uploadify-cancel.png',
                'buttonText': 'Browse',
                'onQueueComplete': function (queueData) {
                senEmail();
                }
            });

My sendEmail function is in Ready function of the page as below:

var senEmail = function() {
                var notes = $("#<%=txtMessage.UniqueID%>");

                var msgbox = $("#cerror");
                $("#cerror").hide();
                $.ajax({
                    type: "POST",
                    url: "ContactMe.aspx/SendEmail",
                    data: "{'message': '" + notes.val() + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",

                    success: function (msg) {
                        if (msg.d == 'Sent') {
            var $tabs = $('#tabs').tabs(); // declare the tabs
            $tabs.tabs("url", 5, "/ContactConfirmation.aspx"); // change the URL of the selected tab
            $tabs.tabs("select", 5 + 1); // refresh the tab content
alert("masTEST3");
            $tabs.tabs("select", 5 ); // refresh the tab content
alert("endTEST");
                        }
                        else {
                            $("#cerror").show();
                            msgbox.html(msg.d);
                        }
                    }

                });
            };

Now the above works fine as in sends an email, but when I am forwarding the user to confirmation page, I get the jquery error : Object Expected and does not forward to next page on same tab(this works on other pages).

appreciate your help.

EDIT:::

here is the IE9 error :

SCRIPT5007: Object expected 
jquery-1.8.3.min.js, line 2 character 24275

and the debugger is on this line:

return!t||t!==!0&&e.getAttribute("classid")===t}})
like image 423
Zaki Avatar asked Jul 12 '26 04:07

Zaki


2 Answers

Found the solution in case someone else has same problem:

I had to destroy the uploadify object when the tab was changing/reloading so all I had to do was before sending email include this line :

$("#file_upload").uploadify("destroy");
like image 91
Zaki Avatar answered Jul 14 '26 18:07

Zaki


I have solved this problem after a fashion.

Calling

$("#file_upload").uploadify("destroy");

after onUploadComplete does work. But if you click on anything else without uploading a file it would crash all javascript on my project. So I started using

$("#file_upload").uploadify("destroy"); 

in several places which caused this new error to arise (something about settings having a null or undefined object). I figure its because I'm trying to call destroy when I'm not able to. Either way that way wasn't working either.

So I opened up uploadify.js and decided to disable some of these options while uploadify is running destroy.

Find the destroy function in uploadify.js and comment this out

    var $this        = $(this),
    swfuploadify = $this.data('uploadify');
    //settings     = swfuploadify.settings;

now uncomment anything below this that is using settings like:

/*/ 
    // Destroy the queue
    if (settings.defaultQueue) {
        $('#' + settings.queueID).remove();
    }

    // Reload the original DOM element
    $('#' + settings.id).replaceWith(swfuploadify.original);

    // Call the user-defined event handler
    if (settings.onDestroy) settings.onDestroy.call(this);
/*/

This will work. And you can still upload pictures and everything. The only down fall is that you lose the options of what these items do. In my situation I'm just uploading one picture at a time so this works for me. You do still have to use

$("#file_upload").uploadify("destroy"); 

before you run any other javascript with in that div. So any tabs or buttons you have other than the uploadify button, you need to have them destroy uploadify when you push those buttons. It has to be the very first action after a click.

like image 29
John Avatar answered Jul 14 '26 19:07

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!