【问题标题】:Load php file file with ajax onclick, without jQuery使用ajax onclick加载php文件文件,没有jQuery
【发布时间】:2014-03-24 18:46:36
【问题描述】:

我正在努力寻找资源,该资源显示了单击某个按钮后如何将 .php 文件加载到页面上的 div 中。几乎所有搜索结果都返回 jQuery 解决方案,而我首先想使用标准 JavaScript 进行尝试。

出于问题的目的,假设我想在用户单击 #loadExample 链接时将 example.php 加载到 #example div 中。

【问题讨论】:

标签: javascript ajax


【解决方案1】:
    <script>

function yourFunction() {
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

  xmlhttp.open("POST","yourpage.php",true);
  xmlhttp.send();

document.getElementById("yourdiv").innerHTML=xmlhttp.responseText;
}


</script>
<div onclick="yourFunction"></div> // or you can use button or hyper link
<div id="yourdiv"></div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-14
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多