[英]Use JQuery Ajax to load static html page to a div tag
I got this working but I need a default page showing before you choose one, how do I do this? 我可以执行此操作,但是在选择一个页面之前,我需要显示一个默认页面,我该怎么做? Also is it possible to hide the page files?
还可以隐藏页面文件吗? So it will not show when you View Source.
因此,当您查看源代码时,它不会显示。
<script src="http://code.jquery.com/jquery-1.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#page1").click(function(){
$('#result').load('latestmembers.php');
//alert("Thanks for visiting!");
});
$("#page2").click(function(){
$('#result').load('Females.php');
//alert("Thanks for visiting!");
});
});
</script>
<ul>
<li><a id="page1" href="#">Latest Members</a></li>
<li><a id="page2" href="#">female members</a></li>
</ul>
<div id="result" style="clear:both;">
</div>
Default will load on load and then you can choose to see just latest members or female members. 默认将加载负载,然后您可以选择仅查看最新成员或女性成员。
$(document).ready(function(){
$('#result').load('latestmembers.php'); // default page
$("#page1").click(function(){
$('#result').load('latestmembers.php');
//alert("Thanks for visiting!");
});
$("#page2").click(function(){
$('#result').load('Females.php');
//alert("Thanks for visiting!");
});
});
JavaScript is client side code, you cannot hide anything from source code. JavaScript是客户端代码,您不能在源代码中隐藏任何内容。
Fitst Question : Default Page 最合适的问题:默认页面
$(document).ready(function(){
$("#page1").click(function(){
$('#result').load('latestmembers.php');
//alert("Thanks for visiting!");
});
$("#page2").click(function(){
$('#result').load('Females.php');
//alert("Thanks for visiting!");
});
// Default page load
$('#result').load('defaultPage.php');
});
Second Question: hide page name 第二个问题:隐藏页面名称
Basically whatever you write on JavaScript is view able by user So you can opt any work around (Dont think its a good idea) You can call a single page like getPage.php
with arguments and desire what content to return by different argument Example Below 基本上,无论你写JavaScript是视图能够通过用户那么你可以选择任何变通(不认为它是个好主意),你可以调用一个页面像
getPage.php
带参数和愿望内容通过不同的参数, 例如下面返回
$(document).ready(function(){
$("#page1").click(function(){
$('#result').load('getPage.php?pid=lm'); // by the pid(page ID) you can check that its for latestmembers.php
//alert("Thanks for visiting!");
});
$("#page2").click(function(){
$('#result').load('getPage.php?pid=fe'); // by the pid(page ID) you can check that its for Females.php
//alert("Thanks for visiting!");
});
// Default page load with no argument
$('#result').load('getPage.php');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.