CodeIgniter/JQuery/Ajax:基于先前选择的值设置下拉列表

CodeIgniter/JQuery/Ajax:基于先前选择的值设置下拉列表,jquery,ajax,codeigniter,select,drop-down-menu,Jquery,Ajax,Codeigniter,Select,Drop Down Menu,我知道有人以各种方式问我这个问题,但我一直未能找到一个明确的答案来解决我的问题。我在应用程序中使用组合if-CI/JQuery/Ajax进行CRUD操作。在我的创建中有多个下拉列表,这些下拉列表是从数据库填充的…每个用户选择的ID在保存时与新记录一起存储。当用户更新该记录时,我需要能够呈现更新页面,填充下拉列表,但设置为选定值。非常感谢您提供有关应用程序中的位置/我如何设置的任何指导。下面是我正在使用的代码片段: JQuery: $.ajax({ url: 'index.php/admin/ge

我知道有人以各种方式问我这个问题,但我一直未能找到一个明确的答案来解决我的问题。我在应用程序中使用组合if-CI/JQuery/Ajax进行CRUD操作。在我的创建中有多个下拉列表,这些下拉列表是从数据库填充的…每个用户选择的ID在保存时与新记录一起存储。当用户更新该记录时,我需要能够呈现更新页面,填充下拉列表,但设置为选定值。非常感谢您提供有关应用程序中的位置/我如何设置的任何指导。下面是我正在使用的代码片段:

JQuery:

$.ajax({
url: 'index.php/admin/getEventById/' + updateId,
dataType: 'json',            
success: function( response ) {
$( '#uEventName' ).val( response.event_name );
$( '#uEventType' ).val( response.eventType_eventType_id ); /*Obviously, this would work fine if I was setting the value of a textbox but this is the ID# of the value I want to have my dropdown default to */
我的看法是:

 <p>
    <label for="uEventName">Event Name:</label>
     <input type="text" id="uEventName" name="uEventName" />
  </p>
  <p>
     <label for="uEventType">Event Type:</label>   <!--I'm populating the dropdown with all values, but need it to be set to value as obtained above (via the response) -->
            <?php        
                $eventtype_options = array();
                foreach($eventtypes as $eventtype){
                $eventtype_options[$eventtype->eventtype_id]=$eventtype->event_type;
                }
                echo "<td>" . form_dropdown('uEventType', $eventtype_options) . "</td>";
            ?>         
            </p>  

在jquery中可能会出现这种情况吗

$('td select[name=uEventType]').val('"'+response.event_name+'"');

Goog午后@jpea,你能详细说明你的答案吗。这个链接不起作用了。