سؤال

I can't get my form to remove from the page when I pass the element to the .remove() function when its inside a $.post call.

Here's my code:

function cancelUpload(form) {
$( "#closeModal" ).dialog({
        resizable: false,
        height:200,
        modal: true,
        buttons: [
        {   
            text: "Yes", 
            click: function() {
                $.post(
                    "misc/removeMedia.php",
                    {location: form.location.value},
                    function(result) {
                        if(result.split('|')[0] == "Success"){
                            $(form).remove();
                            noty({text: result.split('|')[1], type: "information"});

                        } else {
                            noty({text: result.split('|')[1], type: "error"});

                        }

                    },
                    "html"
                    );
                $(this).dialog("close");
            },
            class: "btn btn-success"
        },
        {
            text: "No",
            click: function() {
                $(this).dialog("close");
            },
            class: "btn btn-danger"
        }
        ]
    });
}

If I get rid of the $.post call altogether and just put $(form).remove(), it works. So I KNOW I'm passing in the correct element into the function.

jsFiddle sample: http://jsfiddle.net/4NDFR/

هل كانت مفيدة؟

المحلول

Change:

{location: form.location.value},

to:

{location: $("[name=location]", form).val()},

form is a jQuery object, not a DOM element, so form.location doesn't exist.

FIDDLE

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top