douxi3233 2016-01-16 09:05
浏览 50
已采纳

使用Ajax / jQuery将PHP内容输入到CSS Selector中

I'm creating a script that has a needle which points to various degrees and needs to change dynamically. The number of degrees it needs to move is located in degrees.php (In the page is just a number) I am trying to grab the contents of degrees.php and input it into a CSS Selector to move the needle to the right direction.

What I have so far,

Below is my jquery which grabs the content from wind.php which has a number (139) for example and loads it into the DIV ID #windraw. I've then got it setting an interval for it to keep grabbing the content from that page and updating the CSS on the fly as the content changes. Then loading it into that div id tag and.... The part which I'm stuck on, getting the content from #windraw into the CSS Selector "rotate" (https://github.com/jcubic/jquery.rotate)

jQuery:

<script>
    $(document).ready(function() {
    clearInterval(refreshId);
    $("#windraw").load("../raw/wind.php");
     });

    $(document).ready(function() {
    refreshId = setInterval(function() {
    $("#windraw").load("../raw/wind.php");
    $('#winddirneedle').css('rotate', $"#windraw");
    }, 5000);
    });
</script>

I get the error "Uncaught SyntaxError: missing ) after argument list" In my console debug however.

HTML:

<div id="winddircontain"><div id="winddirneedle" style=""></div></div>

winddircontain is a circle and winddirneedle is the needle that points to the right direction.

I'm quite a beginner in jQuery and only know a handful of it. Could someone please point out whats going wrong with my code? Thanks!

  • 写回答

1条回答 默认 最新

  • doufang8282 2016-01-16 09:21
    关注

    It would be better to use $.get for this I think, rather than loading the result into a DOM element first. Also you have some syntax errors.

    $(document).ready(function () {
      var refreshId = setInterval(function () {
        $.get('../raw/wind.php').done(function (result) {
          $('#winddirneedle').css('rotate', result);
        });
      }, 5000);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题