weixin_33690963 2017-03-16 12:33 采纳率: 0%
浏览 23

简单的PHP Ajax HTML问题

simple question for most of you but for me, being a newbie in php and jquery+ajax, not really: how to replace my index.html with some other html code, requested by ajax call from a php file?

index.html

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>

   <h1>Login page</h1>

   <button id="btn_login">Login</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="javascript.js"></script>

</body>
</html>

javascript.js

$('#btn_login').click(
function(){

   $.ajax({
      url: "login.php",
      type: "GET",
      success: function(data){
          // what to do here?
      }
   });
}
)

login.php

<?php
echo '<div>Succesful login</div>';
?>

TLDR: I want to replace the "Login page" + login button screen to "Succesful login" when clicked the button. Thank you

  • 写回答

3条回答 默认 最新

  • lrony* 2017-03-16 12:40
    关注

    you need to identify -or classify- your <h1> tag to be easily able to change it's contents ,

    <h1 id='title'>Login page</h1>
    

    then , within your ajax call, if success you can change the content like that:

    success: function(data){
        // what to do here?
        if (data) {
            $('#title').html(data);
            $('#btn_login').remove();
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题