无法使用$。获得在Word preSS页Word、preSS

2023-09-10 20:28:47 作者:夏末秋凉i

我试图使用AJAX $。获得()请求在我的字preSS一页显示的计算数据。我还没有决定,如果我要举办不同的服务器我的,或者说话语preSS托管在一个在PHP的计算文件(不认为这会有所作为反正,因为它的数据请求)。我期待添加以下code到无论是header.php文件,甚至更好,在可湿性粉剂管理员创建的页面中:

I'm trying to use an ajax $.get() request to display calculated data within one of my WordPress pages. I haven't decided if I'm going to host the php calculation file on a different server of mine, or the one that WordPress is hosted on (don't think this would make a difference anyway since its a data request). I'm looking to add the following code to either the header.php file, or even better, within the page created in wp-admin:

<script>
  $(document).ready(function(){
      $.get("http://my-other-website.com/parse-list.php",function(data){
          alert(data);
      });
  });
</script>

我知道这是一个基本功能,但我真的难倒就如何并不在Word preSS的工作,但我的工作未托管字preSS其他服务器上时。我测试了jQuery的,以确保它被正确加载,用一个简单的警报(哎),和报警工作得很好。任何人都有这个问题吗?任何帮助将大大AP preciated!

I know this is a basic function, but I'm just really stumped on how it doesn't work within WordPress, but works when on my other server that doesn't host WordPress. I tested jQuery to make sure it was being loaded properly, with a simple alert("hey");, and the alert works just fine. Has anyone else had this problem? Any help would be greatly appreciated!

推荐答案

jQuery的在Word preSS运行在noConflict模式,这意味着全球$快捷方式jQuery是不可用。用下面的替换你的code:

jQuery in WordPress runs in noConflict mode which means the global $ shortcut for jQuery isn't available. Replace your code with the following:

<script>
  jQuery(document).ready(function($){
      $.get("http://my-other-website.com/parse-list.php",function(data){
          alert(data);
      });
  });
</script>