How to call AJAX request on dropdown change event?

后端 未结 2 2088
终归单人心
终归单人心 2020-12-11 09:36

index.php




        
相关标签:
2条回答
  • 2020-12-11 09:49

    Assign the href as list item values in drop down. Onchange of dropdown, make the ajax call.

    class name "ajax" is just for reference (useful, if you want to handle event for morethan one element).

    0 讨论(0)
  • 2020-12-11 09:55

    Change your code like this:

    jQuery('#dropdown_id').live('change', function(event) {
        jQuery.getJSON($(this).val(), function(snippets) {
            for(var id in snippets) {
                // updated to deal with any type of HTML
                jQuery('#' + id).html(snippets[id]);
            }
        });
    });
    

    And your dropdown should look like this:

    <select id="dropdown_id">
      <option value="one.php">One</option>
      <option value="two.php">Two</option>
    </select>
    
    0 讨论(0)
提交回复
热议问题