2010-08-11 30 views
0

我有一堆想要在页面内动态加载的链接。我不想为每个链接写出大量声明,而是希望从属性中获取URL并将其传递到我需要的地方。将Jquery和Ajax作为变量传递一个URL

下面的代码工作,如果我把一个地址,而不是变量名linkURL,所以我知道代码的作品。萤火虫显示它看起来在第一个正确的网址,但是当它到达

.load('linkURL .columnWide');

部分它开始寻找linkURL

// AJAXin links 

// Click on link within id with ending of ASPX triggers this 
$('#element a[href$=aspx]').click(function(e) { 

    // Grab the href attribute and use it as linkURL variable 
    var linkURL = $(this).attr('href'); 
    // AJAX 
    $.ajax({ 

    // Use the variable linkURL as source for AJAX request 
    url: linkURL, 
    dataType: 'html', 

    success: function(data) { 
     // This is where the fetched content will go 
     $('.result1') 
      // HTML added to DIV while content loads 
      .html('<div id="spinningLoader"><img class="loader" src="spinnerBlack.png" alt="spinnerBlack" width="100" height="100" /></div> ') 
      // Load from this URL this class 
      .load('linkURL .columnWide'); 

     // See above 
     $('.result2') 
      .html('<div id="spinningLoader"><img class="loader" src="spinnerBlack.png" alt="spinnerBlack" width="100" height="100" /></div> ') 
      .load('linkURL .columnNarrow'); 

     // It worked mother flipper 
     $.print('Load was performed.'); 
    } 
    }); 
}); 

编辑:我可能不应该公布在链接的东西我的S3桶:■

+0

什么不起作用?问题是什么? – 2010-08-11 11:26:20

+0

您是否尝试过使用Firebug或Opera Dragonfly调试此代码?你应该检查'linkURL'是否保留地址。 – Ventus 2010-08-11 11:28:28

+0

我在这里看不到有什么问题? – 2010-08-11 11:28:30

回答

2

你需要修改你load线从而​​

+0

干杯拉撒路,完美的作品! – Reynish 2010-08-11 11:36:29

+0

很高兴提供帮助,请记住,Javascript(实际上很多编程语言)不会分析字符串文字中的变量名称。 – Lazarus 2010-08-11 11:41:35