Automatic update of select menu after jquery input database

Automatic update of select menu after jquery input database

Hello,

I'm having a little issue and i don't know how to let it work, i will explain!

I have enough PHP knowledge, only my knowledge of jquery is a bit poor...

I'm working on a website and i have started a backoffice thats adding menu items into a database, if i put a new menu item it wil open a jquery window and add the menu item in the database.

So i think i need to do this in JSON

It's also possible to add a sub menuitem to an existing menuitem, this is standing in the form in a <selection>, now i want to get the next...

After adding a new item into the database, i want without refreshing my page to add the new record into the <selection> menu, i have tryed a few things from the internet, only it's not working for me.

The next code i'm using to add the menuitem into database

  1. var SITE_URL    = "http://xxxxxx/~martinm";

    $$.ready(function() {
        $( "#dialog_add_menu" ).dialog({
            autoOpen: false,
            modal: true,
            width: 900,
            open: function(){ $(this).parent().css('overflow', 'visible'); $$.utils.forms.resize() }
        }).find('button.submit').click(function(){
            var $el = $(this).parents('.ui-dialog-content');
            if ($el.validate().form()) {
                          
                var filename        = SITE_URL+"/admin/requests/menu.php";
               
                $.ajax
                ({
                    type: "POST",
                    url: filename,
                    data: "do=add&"+$('form#menu').serialize()+"",
                   
                    success: function(msg)
                    {
                        document.getElementById("return_message").innerHTML = msg;
                    }
                });
               
                $el.find('form')[0].reset();
               
                $el.dialog('close');
            }
        }).end().find('button.cancel').click(function(){
            var $el = $(this).parents('.ui-dialog-content');
            $el.find('form')[0].reset();
            $el.dialog('close');;
        });
       
        $( ".open-add-menu-dialog" ).click(function() {
            $( "#dialog_add_menu" ).dialog( "open" );
            return false;
        });
    });







































This is working fine, now i'm looking for a peace of code in jQuery and a little example how i can automaticly reload the <select> menu with the new added data whats standing in a mysql database.

Now i have founf this script that i whant to comunnicate with a PHP script

  1. $.ajax({
                     type: "GET",
                     url: filename2,
                     async: false,
                     beforeSend: function(x) {
                      if(x && x.overrideMimeType) {
                       x.overrideMimeType("application/j-son;charset=UTF-8");
                      }
                 },
                 dataType: "json",
                 success: function(data){
                    //do your stuff with the JSON data
                    alert(data);
                 }
                });













But the alert doenst get up with the JSON information that i have added

JSON in PHP script

  1. <?php
    class A {
        public $a = 1;
        public $b = 2;
        public $collection = array();

        function  __construct(){
            for ( $i=3; $i-->0;){
                array_push($this->collection, new B);
            }
        }
    }

    class B {
        public $a = 1;
        public $b = 2;
    }

    echo json_encode(new A);
    ?>
























I hope i have explained this a little bit clear...

If you have anny questions please let me know!

I want to thank you for taking the time for reading my post (maybee in poor english... sorry for that im from the netherlands)

Greetings Martin