【问题标题】:How to Call the one php page content and display it another php page using ajax如何调用一个php页面内容并使用ajax显示另一个php页面
【发布时间】:2014-07-23 20:09:59
【问题描述】:

我有索引页面,因为我有 2 个按钮“员工详细信息”和“学生详细信息” 当我点击“StaffDetails”时,“staffDetails.php”的内容应该显示在 index.php 中

同样,“STudent details”也是如此

Ajax 函数:

function search1()
    {       $.ajax({
                    Type:'GET',
                    url:'StaffDetails.php',
                    success:function(html)
                    {
                        document.getElementById("StaffDetails").innerHTML=html;
                    },
                })
    }

【问题讨论】:

  • 你有什么问题?
  • 您的语法不正确...所以在 ajax 调用的末尾没有分号。 index.php 和 staffdetails.php 是否在同一目录级别?而不是 document.getElementById 使用:$("#StaffDetails").html(html);
  • 那你为什么不用$.load()呢?

标签: php html ajax


【解决方案1】:

这里有一个完整的 ajax 函数这样使用,并在将来为您提供全面的帮助

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-1.7.min.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function search1(){
$.ajax({  

  type: "POST",  
  url:"StaffDetails.php",  

  beforeSend: function()
  {
  },
  success: function(resp)
  {  

    $("#StaffDetails").html(resp);

  }, 

  complete: function()
  {
  },

  error: function(e)
  {  
  alert('Error: ' + e);  
  }  
  }); 
}

function search2(){
 $.ajax({  

  type: "POST",  
  url:"StudentDetails.php",  

  beforeSend: function()
  {
  },
  success: function(resp)
  {  

    $("#StudentDetails").html(resp);

  }, 

  complete: function()
  {
  },

  error: function(e)
  {  
    alert('Error: ' + e);  
  }  
}); 
}
</script>
</head>

<body>
<input type="button" value="Staff Details" onclick="search1()" />
<input type="button" value="Student Details" onclick="search2()" />
<div id="StaffDetails">
</div>
<div id="StudentDetails">
</div>
</body>

这里是完整的 ajax 工作和测试示例,希望现在没有问题。 谢谢!

【讨论】:

  • 请解释如何使用它,为什么它应该工作,任何需要注意的陷阱等。链接到进一步的文档也是一件好事。
  • php echo $row_values['S_AdmissionID']?>
猜你喜欢
  • 2013-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-23
  • 1970-01-01
相关资源
最近更新 更多