2011-10-05 126 views
2

任何想法为什么这是行不通的?jQuery加载中未加载内容

$('a.uiAjaxModal').click(function (e) { 

      e.preventDefault(); 

      $modalHtml = '<div class="uiModalWrapper"><div class="uiModal"><!--content here--></div></div>'; 

      $($modalHtml).find('.uiModal').load($(this).attr('href')); 

      $('body').append($modalHtml); 

     }); 

<a class="uiAjaxModal" href="/Organisations/New">New</a> 

它追加模式罚款,但内容没有加载,我在控制台没有错误!

另外我怎么能这样做,以便modalHtml只是附加到一个点击事件像我在我的代码中完成,但确保只有一个它的实例可以存在于屏幕上?

+0

提示:你是谷歌浏览器本地网页上检查? load()现在可以在使用谷歌浏览器的本地页面上运行。这让我发现,直到我发现。 – Arda

回答

0

我结束了使用.ajax()代替其工作正常,并有更好的选择

0

使字符串到jQuery对象,因为你是在AJAX使用jQuery对象,但你追加的是一个字符串,而不是一个jQuery参考:

$('a.uiAjaxModal').click(function (e) { 

     e.preventDefault(); 

     $modalHtml = $('<div class="uiModalWrapper"><div class="uiModal"><!--content here--></div></div>'); 

     $modalHtml.find('.uiModal').load($(this).attr('href')); 

     $('body').append($modalHtml); 

    }); 

<a class="uiAjaxModal" href="/Organisations/New">New</a> 

,如果你只希望它运行一次,然后在jquery中查看.one()方法。

0

我认为选择器无效。请试试

$('。uiModalWrapper')。find('。uiModal')。load($(this).attr('href'));