2011-06-23 119 views
0

我在ASP.NET MVC 3應用程序中使用$.get()以異步獲取數據庫響應。我得到的響應正確返回,並基於我在一個字符串變量中生成我的HTML的響應,最後將其附加到已經在我的標記頁面上的div。在調試模式下,它向我展示了完整的HTML創建,但它不會在瀏覽器中呈現。JQuery不呈現HTML

這裏是我的示例代碼

$.get("/Modules/FetchModuleActionsByModuleID", { ModuleID: ModuleID }, function (response) 
{ 
    if (response.replace(/"/g, '') != '{d:[]}' && response.replace(/"/g, '') != '{d:null}' && response.replace(/"/g, '') != '' && response != '') 
    { 
     var actions = eval('(' + response + ')'); 
     var moduleHtml=""; 
     if (actions.length > 0) 
     { 
      for (i = 0; i < actions.length; i++) 
      { 

       moduleHtml += "<div class='moduleFieldSetting'>"; 
       moduleHtml += "<span class='pdRL10x2 fl'><input type='checkbox' name='" + ModuleName + "_Actions' value='" + actions[i].ActionID + "' /></span>"; 
       moduleHtml += "<span>" + actions[i].ActionName + "</span>"; 
       moduleHtml += "<div class='clear'></div>"; 
       moduleHtml += "</div>"; 
      } 

      moduleHtml += "<div class='fr mt15'>"; 
      moduleHtml += "<span class='fr'><input type='button' class='inpuButtonAdd' value='Save' /> "; 
      moduleHtml += "<input type='button' class='inpuButtonAdd' value='Cancel' /> "; 
      moduleHtml += "</span>" 
      moduleHtml += "</div>"; 

      moduleHtml += "</div>"; 

      moduleHtml += "<div class='clear'></div>"; 
      moduleHtml += "</div>"; 
      moduleHtml += "</div>"; 
      moduleHtml += "<div class='clear'></div>"; 


      $("#divModuleDetails").append(moduleHtml); //appending to div 
     } 
    } 
}); 

可能是什麼造成的?

+0

此問題僅限於IE。在FireFox中工作 – Vivek

+0

什麼是您使用的IE版本? – bhagyas

+0

您是否試過修剪'moduleHTML'直到問題消失?這至少會讓你對這個問題有所瞭解。 –

回答

0

看看這個行:

moduleHtml += "</span>" 

我認爲這個問題是腳本仍然僅打印的跨度,但也許沒有什麼:)

反正簽下面的腳本優化,我認爲它應該工作;)

$.get("/Modules/FetchModuleActionsByModuleID", { ModuleID: ModuleID }, function (response) 
{ 
    if (response.replace(/"/g, '') != '{d:[]}' && response.replace(/"/g, '') != '{d:null}' && response.replace(/"/g, '') != '' && response != '') 
    { 
     var actions = eval('(' + response + ')'); 
     var moduleHtml; 
     if (actions.length > 0) 
     { 
      for (i = 0; i < actions.length; i++) 
      { 

       moduleHtml += "<div class='moduleFieldSetting'>" 
       + "<span class='pdRL10x2 fl'><input type='checkbox' name='" 
       + ModuleName 
       + "_Actions' value='" 
       + actions[i].ActionID 
       + "' /></span>" 
       + "<span>" 
       + actions[i].ActionName 
       + "</span>" 
       + "<div class='clear'></div>" 
       + "</div>"; 
      } 

      moduleHtml += "<div class='fr mt15'>" 
      +"<span class='fr'><input type='button' class='inpuButtonAdd' value='Save' /> " 
      + "<input type='button' class='inpuButtonAdd' value='Cancel' /> " 
      +"</span>" 
      + "</div>" 
      + "</div>" 
      + "<div class='clear'></div>" 
      + "</div>" 
      + "</div>" 
      + "<div class='clear'></div>"; 


      $("#divModuleDetails").append(moduleHtml); //appending to div 
     } 
    } 
}); 
+0

然後...確保你有最新的jQuery版本;) – memento