weixin_33674976 2015-03-02 07:52 采纳率: 0%
浏览 47

页面未使用AJAX加载

I am new to AJAX & trying to load a page (test.html) through ajax in to a DIV. I just want to know that is it possible to use AJAX without PHP server (which I am not using at present) or is there any error in the code:

My index.html file is as under:

<! doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="css/hwcb.css">
</head>
<body>
      <input type="button" value="Load" class=”loadpage1”/>
       <div id="loadpagea1"></div>

  <script src="jquery.js"></script>
<script src="css.js"></script>
<script src="main.js"></script>
  </body>
  </html>

my test.html file:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
We belongs to a great nation
</body>
</html>

main.js page:

$('.loadpage1').click(function(){
$.ajax({
url:'test.html',
success:function(data){
$('#loadpagea1').html(data);
}
});
});
  • 写回答

4条回答 默认 最新

  • weixin_33728268 2015-03-02 07:56
    关注

    I just want to know that is it possible to use AJAX without PHP server

    Assuming by this you mean without any server in general, then no it is not. You cannot make an AJAX request to the local file system as it will be blocked by the browsers' security settings.

    You need to make the request to a server, either local or remote. I would suggest setting up an XAMP server for PHP, or IIS for ASP.Net.

    评论

报告相同问题?