首先:不要回到黑暗的时代…不要使用相同的脚本来生成HTML并响应ajax请求。
我对您要执行的操作一无所知…让我更改您的代码,这样至少可以使您理解并记录正在发生的事情。似乎问题在于您正在从成功处理程序中调用location.reload。
// ajax.php-如果name参数是145,则输出2,否则输出1(????)
<?php$score = "1"; $userAnswer = $_POST['name']; if ($_POST['name'] == "145"){ $score++;} echo $score; ?>// test.html
<script type="text/javascript"> $(document).ready(function() { $("#raaagh").click(function(){ $.ajax({ url: 'ajax.php', //This is the current doc type: "POST", data: ({name: 145}), success: function(data){ // Why were you reloading the page? This is probably your bug // location.reload(); // Replace the content of the clicked paragraph // with the result from the ajax call $("#raaagh").html(data); } }); });});</script><p id="raaagh">Ajax Away</p>


