我正在尝试以模式对话框中显示的形式使用 getJSON 更新 div 控件(#test)。每次用户单击定义的链接时都会显示该对话框。这是调用的函数:
// Displays modal dialog with a form
function job_description(job_id) {
    $('<div id="server-form"></div>').load('/description_form').dialog(
        {
            position: { 
                my: 'top top',
                at: 'top top',
                offset: '0 100',
                of: $('body')
            },
            width: 650,
            modal:true,
            resizable: false,
            title: 'Job description details',
            buttons: { 
                "close": {
                class: "btn btn-primary",
                text: "Close",
                click: 
                    function() {
                        $( this ).remove();
                    }
                }
            },
            close: function(event,ui) {
                $(this).remove();
            }
    });
    var response = $.ajax({
      type: 'GET',
      url: '/descriptions_list/'+job_id,
      cache: false,
      datatype: 'json',
      success: function(response){
               var obj = $.parseJSON(response); 
               //console.log(obj.description.title);
               $('#test').html(obj.description.title);
          },
      error: function(msg) {
                alert('error: '+msg);
      }
    });
}
我知道 ajax 调用始终有效(我检查了控制台,但从未收到警报),但 #test div 有时不会更新。它随机发生。开头的 load() 方法调用了一个实际加载表单的 REST 服务,然后使用 ajax 从另一个 url 拉取一些数据。#test div 也在引导轮播中。这是我要更新的 div 部分:
<div id="wrapper">
<div id="description-editor" class="carousel slide" style="padding-left: 20%;padding-right: 20%">
  <!-- Carousel items -->
  <div class="carousel-inner">
    <form>
      <div class="item well" style="height: 500px">
        <h3>Title</h3><br/>
        <div id="test" style="width: 300px; height: 200px">I should get updated...</div>
      </div>
      <div class="item well" style="height: 500px">
        <h3>Some other info</h3><br/>
        <p>To be completed</p>
      </div>
    </form>
  </div>
  <!-- Carousel nav -->
  <a class="carousel-control left" href="#description-editor" data-slide="prev" data-interval="">‹</a>
  <a class="carousel-control right" href="#description-editor" data-slide="next" data-interval="">›</a>
</div>
</div>
我正在努力弄清楚为什么#test div 在调用成功时并不总是得到更新(总是如此)。我尝试使用 async: false,但这也无济于事……我使用的是 jquery 1.7.1。
谢谢。