2012-04-08 59 views
0

好吧,大家希望我可以有效地解释这一点,所以在这里。链接到ajax div

我有一个无序的列表,其中每个列表项通过jquery在我的“服务”页面上点击将html页面加载到div上。

基本上在头版我有一对夫妇的链接,当点击一个,我需要它去“服务”,并看到div中适当的HTML页面。

这里还挺如何代码:

服务Page:

<ul id="service-nav"> 

      <li><a id="interlocking" href="#">Interlocking</a></li> 
      <li><a id="pool-backfill" href="#">Pool Backfill</a></li> 
      <li><a id="poured-concrete" href="#">Poured Concrete</a></li> 
      <li><a id="parging" href="#">Parging</a></li> 
      <li><a id="custom-land" href="#">Custom Landscaping</a></li> 
      <li><a id="snow-rem" href="#">Snow Removal</a></li> 
      <li><a id="excavation" href="#">Excavation</a></li></ul> 
     </ul> 

    <div id="right-area"> <!-- This is where we load the relevant html's --> 
    </div> 

头版:

 <ul> 
      <li><a href="services.php?token=interlocking">Interlocking</a></li> 
      <li><a href="services.php?token=pool-backfill">Pool Backfill</a></li> 
      <li><a href="services.php?token=poured-concrete">Poured Concrete</a></li> 
     </ul> 

这里是我的jQuery供大家参考:

<script type="text/javascript"> 
$(document).ready(function() { 

    $(function(){ 
     var token = window.location.toString().split("=")[1]; 

     $("#" + token).click(); 

     });​ 


    $('#interlocking').click(function() { 
     $('#right-area').load('http://romanstonedesigns.com/new/services/interlocking.php', function() { 
     }); 
    }); 

    $('#pool-backfill').click(function() { 
     $('#right-area').load('http://romanstonedesigns.com/new/services/pool-backfill.php', function() { 
     }); 
    }); 

    $('#poured-concrete').click(function() { 
     $('#right-area').load('http://romanstonedesigns.com/new/services/poured-concrete.php', function() { 
     }); 
    }); 

    $('#parging').click(function() { 
     $('#right-area').load('http://romanstonedesigns.com/new/services/parging.php', function() { 
     }); 
    }); 

    $('#custom-land').click(function() { 
     $('#right-area').load('http://romanstonedesigns.com/new/services/custom-landscaping.php', function() { 
     }); 
    }); 

    $('#excavation').click(function() { 
     $('#right-area').load('http://romanstonedesigns.com/new/services/excavation.php', function() { 
     }); 
    }); 

    $('#snow-rem').click(function() { 
     $('#right-area').load('http://romanstonedesigns.com/new/services/snow-removal.php', function() { 
     }); 
    }); 







}); 

</script> 
+0

相关的HTML位于何处?如果你能证明这一点,我们可以找出如何通过ajax调用来访问它。 – 2012-04-08 01:42:37

回答

0

好吧,假设我们想要显示互锁页面,所以你的头版应该是这样的:

1.

<ul> 
     <li><a href="services.php?token=Interlocking">Interlocking</a></li> 
    </ul> 

2.In您的服务页面,jQuery代码应该是:

<script type="text/javascript"> 


$(function(){ 




    $('#interlocking').click(function() { 
    $('#right-area').load('http://romanstonedesigns.com/new/services/interlocking.php', function() { 
    }); 
}); 

$('#pool-backfill').click(function() { 
    $('#right-area').load('http://romanstonedesigns.com/new/services/pool-backfill.php', function() { 
    }); 
}); 

$('#poured-concrete').click(function() { 
    $('#right-area').load('http://romanstonedesigns.com/new/services/poured-concrete.php', function() { 
    }); 
}); 

$('#parging').click(function() { 
    $('#right-area').load('http://romanstonedesigns.com/new/services/parging.php', function() { 
    }); 
}); 

$('#custom-land').click(function() { 
    $('#right-area').load('http://romanstonedesigns.com/new/services/custom-landscaping.php', function() { 
    }); 
}); 

$('#excavation').click(function() { 
    $('#right-area').load('http://romanstonedesigns.com/new/services/excavation.php', function() { 
    }); 
}); 

$('#snow-rem').click(function() { 
    $('#right-area').load('http://romanstonedesigns.com/new/services/snow-removal.php', function() { 
    }); 
}); 

    var token = window.location.toString().split("=")[1]; 
    $("#" + token).click(); 

    }); 

再见!

+0

你能给我一个jquery函数的例子吗? – onei0120 2012-04-08 01:49:36

+0

当然!给我5分钟 – mleger45 2012-04-08 01:53:16

+0

惊人的,非常感谢你 – onei0120 2012-04-08 02:11:03