Need help? Check out our Support site, then


Ajax in plugin menu.

  1. I am trying to make a plugin menu using a simple ajax function. The form has two selection options. The second selection option is populated by the database based on what is selected in the first option. While this code works just fine outside of wordpress, I can't for the life of me understand any of the tutorials available on using ajax with wordpress, none of them even make remotely any sense to me.

    The form:

    <div id="wrapper">
    <h1>First dropdown selection based on display second dropdown</h1>
    <form action="" method="post">
    <p><label>Main Menu :</label>
    <select name="main_menu_id" id="main_menu_id">
    <option value="">Select</option>
    <?php
    // Connect to database.
    	$connect = mysqli_connect('<!----My connection info---->')
    	$q = mysqli_query($connect, "SELECT cfid,cfname FROM categoryfiles ORDER BY cfid");
    while($row = mysqli_fetch_array($q)) {
    	echo '<option value="' . $row['cfname'] . '">' . $row['cfname'] . '</option>';
    }
    ?>
    </select>
    </p>
    <p><label>Sub Menu:   </label>
    <select name="sub_menu_id" id="sub_menu_id"></select>
    </p>
    </form>
    </div>

    The script:

    $(function() {
    	$("#main_menu_id").bind("change", function() {
    		$.ajax({
    			type: "GET",
    			url: "get_sub_category.php",
    			data: "main_menu_id="+$("#main_menu_id").val(),
    			success: function(html) {
    				$("#sub_menu_id").html(html);
    			}
    		});
    	});
    });

    The get_sub_category.php:

    <?php
    
    	// Connect to database.
    	$connect = mysqli_connect('<!----My connection info---->')
    
    	$id = $_GET['main_menu_id'];
    	$q = mysqli_query($connect, "SELECT sfid, sfname FROM subjectfiles WHERE sfcategory='" . $id . "' ORDER BY sfname");
    	while($row = mysqli_fetch_array($q)) {
    
    	echo '<option value="' . $row['sfname'] . '">' . $row['sfname'] . '</option>';
    
    	}
    ?>

    Linking me to docs and other tutorials will not help. I've seen them all and they are just not making sense. How do I make this simple ajax setup work? Any help is appreciated.

    The blog I need help with is dmattheww82.wordpress.com.

  2. You can't do that on this blog http://dmattheww82.wordpress.com/

  3. Please read this comparison http://en.support.wordpress.com/com-vs-org/

  4. It's on not on that blog. I just made that blog to post here. It's on a separate wordpress blog I am working on with a friend.

  5. It's not even on the wordpress servers. It's on my server.

  6. Right. We provide support only for free blogs provided by and hosted by WordPress.COM. We do not provide support for any local installs WordPress.ORG software here. WordPress.com and WordPress.org are completely separate and different http://support.wordpress.com/com-vs-org/

    If you don't have a username account at WordPress.ORG click http://wordpress.org/support/ and register one on the top right hand corner of the page that opens, so you can post to the support forums there and receive advice from WordPress.ORG bloggers.

You must log in to post.

About this Topic