2016-11-09 49 views
-1

我遇到问题。我有一些代码需要使用ajax来在单击特定链接时显示结果。它获得按钮的id并使用ajax在数据库中搜索该id。此刻,我可以发布到下一页,但我需要同时加载结果,以便在页面上发帖,说明该页面是否有确认信息,并显示在索引页上。同时发布和加载

的index.php

<script type="text/javascript" src="jquery.min.js"></script> 

<button class="Stylebut" style="background-color:yellow;" id="500" onClick="reply_click(this.id)">time</button> 

<script type="text/javascript"> 
function reply_click(clicked_id) 
{ 
    $.ajax({ 
    url: 'load.php', //This is the current doc 
    type: "POST", 
    dataType:'json', // add json datatype to get json 
    data: ({name: clicked_id}), 
    success: function(data){ 
     console.log(data); 
     alert("hello") 
    } 
}); 

} 
</script> 

load.php

<?php 
$userAnswer = $_POST['name']; 
?> 
<p>This text needs to show on the page and anything else that loads up</p> 

我需要将数据发送到页面,并使用数据加载页面,并使用AJAX打印第一页。感谢您的帮助

+0

欢迎SO。 请阅读[我可以问哪些主题](http://stackoverflow.com/help/on-topic) 和[如何提出一个好问题](http://stackoverflow.com/help/how-to - 问) 和[完美的问题](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) 以及如何创建[最小,完整和可验证的例子] (http://stackoverflow.com/help/mcve) SO是**不是免费的编码或代码转换或调试或教程或库查找服务** ___在这里我们修复你的尝试,我们不会尝试你的fixes___ – RiggsFolly

回答