繁体   English   中英

Ajax PHP不返回更新的变量

[英]Ajax PHP not returning updated variable

我很抱歉,之前也曾问过类似的问题-尝试了很多事情,无法弄清楚为什么它不起作用。 我通过点击功能调用ajax。 我似乎无法获得返回的jList值,从而更新了主页中的变量。

这是不起作用的简化版本。 PHP文件:

<?php

echo <<<END
  <script type="text/javascript">

    jList = "ELLO!!??";
    //alert(jList);

  </script>
END;

?>

主页是这样的:

<script>
var jList = false;
...
...
...

function loadMore(listFile, nextS, nextE) {
  url = 'files/php/jList.php?l='+ listFile +'&s='+ nextS +'&e='+ nextE;

  $.ajax({
      url: url,
      type: 'POST',
      success:function(results) {
          console.log(jList); // can't get the var to update with the value from PHP 
      }
  });

}
...
...
...
  $("#readMore").unbind("click").click(function(e){
    loadMore(listFile, nextS, nextE);
   });
</script> 

连续返回(console.logs)最初在主页上设置的值。 我想念什么? 谢谢。

您的PHP应该是:

<?php
echo 'jList = "ELLO!!??";';
?>

jQuery应该是:

$.getScript(url, function() {
    console.log(jList);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM