Jump to content

learning jquery ui - dialog delete record


quasiman

Recommended Posts

Hi, I'm trying to learn jquery ui (without much of a javascript background), and I think I'm pretty close to what I want.....but the error I'm seeing doesn't make much sense to me.  Here's my code first:

        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script>
            $(function() {
                var contactid = "<?php echo $_GET['contactid']; ?>";
                $( "#dialog-confirm" ).dialog({
                    autoOpen: false,
                    resizable: false,
                    height:290,
                    width:450,
                    modal: true,
                    buttons: {
                        "Delete": function() {
                            $.ajax({
                                type: "POST",
                                url: 'delete-contact.php',
                                data: {contactid:  contactid},
                                dataType: 'json',
                                context: $(this),
                                cache: false,
                                statusCode: {
                                    404: function() {
                                        alert("page not found");
                                    },
                                    200: function() {
                                        alert("200 success");
                                    }
                                }
                            }).then(
                            function(){ alert("$.ajax succeeded"); },
                            function(){ alert("$.ajax failed!"); }
                        );
                        },
                        Cancel: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                });
                $( "#confirm-delete" )
                .button()
                .click(function() {
                    $( "#dialog-confirm" ).dialog( "open" );
                });
            });
        </script>

Now, you can see I have a few alerts in there, and I'm getting two to popup, first '$.ajax failed!', followed by '200 success'.  I check Firebug and I can see the post successful (to a dummy file just echoing the $_POST), so I don't understand why I'm seeing the deferred.then() return an error.

 

Any ideas for jquery newbie?   :)

Link to comment
https://forums.phpfreaks.com/topic/278110-learning-jquery-ui-dialog-delete-record/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.