簡體   English   中英

Ajax加載同一頁面的內容

[英]Ajax loading content of same page

我只是復制粘貼代碼表w3school

load_second.php我只是加載gethint.php,其余代碼與w3school中的相同。

function loadDoc() {
  var xhttp;
  if (window.XMLHttpRequest) {
    // code for modern browsers
    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("demo").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET", "gethint.php", true);
  xhttp.send();
}

gethint.php具有此代碼<?php echo "ghjghjghj";?>

但是當我在本地主機上運行它時,它無法正常工作。

我正在使用xampp。 我在本地主機上運行load_second.php,單擊“更改內容”時會發生以下情況, 它顯示另一個“更改內容”按鈕

嘗試使用jQuery的Ajax。 我認為它更簡單。

$.get( "gethint.php", function( data ) {
   $( "#demo" ).html( data );
   console.log( "Load was performed." );
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM