href
geçerli sayfaya aynı sunucuda olan bir sayfaya bir bağlantı olduğunda
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a").click(function(event) {
event.preventDefault();
var href = $(this).attr('href');
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("siteloader").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", href, true);
xhttp.send();
</script>
</head>
Ancak bu sadece çalışır. Örneğin, href
https://www.facebook.com
olsaydı hiçbir şey olmazdı, ancak eğer log.txt
ise, içeriğim onu adlandırılmış bir dosyam olduğu gibi yüklerdi.
Nasıl sayfamda harici web içeriğini görüntüleyebilir?
Sorgulama ve ajax için çok yeni. Üçüncü parti web sitelerinden veri almak için böyle bir komut dosyasının nasıl yazılacağını öğrenebileceğim bir öğretici veya bir web sitesi önerebilir misiniz? – Ankush
http://www.w3schools.com/jquery/ajax_ajax.asp – Max