te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - jQuery dollar sign is undefined - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery dollar sign is undefined - Stack Overflow

programmeradmin3浏览0评论

In my quest to get historical information, i tried using the below code. Chrome debugger says that Uncaught ReferenceError: $ is not defined. Can you suggest a fix, i'm really stuck. I just need this to work on Chrome, and I am tapping into YQL and Yahoo API.

here is the jsFiddle /

<html>
  <head>      
    <script type='text/javascript' src=''></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {'packages':['annotatedtimeline']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();

        /* historical data code that breaks */
        var url = '';
        var startDate = '2012-01-01';
        var endDate = '2012-01-08';
        var jsonData = encodeURIComponent('select * from yahoo.finance.historicaldata where symbol in ("YHOO","AAPL","GOOG","MSFT") and startDate = "' + startDate + '" and endDate = "' + endDate + '"');
        $.getJSON(url, 'q=' + data + "&env=http%3A%2F%2Fdatatables%2Falltables.env&format=json", callback);

        data.addColumn('date', 'Date');
        data.addColumn('number', 'Sold Pencils');
        data.addColumn('string', 'title1');
        data.addColumn('string', 'text1');

        data.addColumn('number', 'Sold Pens');
        data.addColumn('string', 'title2');
        data.addColumn('string', 'text2');      // not on the fly


        data.addRows([
          [new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined],
          [new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined],
          [new Date(2008, 1 ,3), 55022, undefined, undefined, 50766, undefined, undefined],
          [new Date(2008, 1 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'],
          [new Date(2008, 1 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined],
          [new Date(2008, 1 ,6), 33322, undefined, undefined, 39463, undefined, undefined]
        ]);

        var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
        chart.draw(data, {displayAnnotations: true});
      }
    </script>
  </head>

  <body>
    // Note how you must specify the size of the container element explicitly!
    <div id='chart_div' style='width: 700px; height: 240px;'></div>

  </body>

In my quest to get historical information, i tried using the below code. Chrome debugger says that Uncaught ReferenceError: $ is not defined. Can you suggest a fix, i'm really stuck. I just need this to work on Chrome, and I am tapping into YQL and Yahoo API.

here is the jsFiddle http://jsfiddle/pCK5q/1/

<html>
  <head>      
    <script type='text/javascript' src='http://www.google./jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {'packages':['annotatedtimeline']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();

        /* historical data code that breaks */
        var url = 'http://query.yahooapis./v1/public/yql';
        var startDate = '2012-01-01';
        var endDate = '2012-01-08';
        var jsonData = encodeURIComponent('select * from yahoo.finance.historicaldata where symbol in ("YHOO","AAPL","GOOG","MSFT") and startDate = "' + startDate + '" and endDate = "' + endDate + '"');
        $.getJSON(url, 'q=' + data + "&env=http%3A%2F%2Fdatatables%2Falltables.env&format=json", callback);

        data.addColumn('date', 'Date');
        data.addColumn('number', 'Sold Pencils');
        data.addColumn('string', 'title1');
        data.addColumn('string', 'text1');

        data.addColumn('number', 'Sold Pens');
        data.addColumn('string', 'title2');
        data.addColumn('string', 'text2');      // not on the fly


        data.addRows([
          [new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined],
          [new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined],
          [new Date(2008, 1 ,3), 55022, undefined, undefined, 50766, undefined, undefined],
          [new Date(2008, 1 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'],
          [new Date(2008, 1 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined],
          [new Date(2008, 1 ,6), 33322, undefined, undefined, 39463, undefined, undefined]
        ]);

        var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
        chart.draw(data, {displayAnnotations: true});
      }
    </script>
  </head>

  <body>
    // Note how you must specify the size of the container element explicitly!
    <div id='chart_div' style='width: 700px; height: 240px;'></div>

  </body>
Share Improve this question asked Nov 20, 2012 at 20:59 bouncingHippobouncingHippo 6,04023 gold badges71 silver badges110 bronze badges 7
  • 5 Where is your jQuery reference? – SpYk3HH Commented Nov 20, 2012 at 21:00
  • 1 Are you importing jquery? or another library that uses $? – AJak Commented Nov 20, 2012 at 21:01
  • 3 Select 'jQuery' from the dropdown on the left in your JsFiddle. Currently it's Mootools... – ahren Commented Nov 20, 2012 at 21:02
  • 1 Please learn how to use jsFiddle: jsfiddle/pCK5q/2. Also, you never define callback anywhere. – Felix Kling Commented Nov 20, 2012 at 21:05
  • @FelixKling, how should i define the callback then? – bouncingHippo Commented Nov 20, 2012 at 21:06
 |  Show 2 more ments

3 Answers 3

Reset to default 6

Just add a reference to the JQuery source before your script:

<script src="http://code.jquery./jquery.min.js"></script>

Add this line:

google.load("jquery", "1.7.1");

Just under this one you already have:

google.load('visualization', '1', {'packages':['annotatedtimeline']});

This will load jQuery from the Google jsapi you already use. This is the best solution regarding your code.

Try adding a jQuery reference:

<head>      
    <script type='text/javascript' src='http://code.jquery./jquery-1.8.3.min.js'></script>
    <script type='text/javascript' src='http://www.google./jsapi'></script>
    <script type='text/javascript'>

OR (but i thinks this wont work because you are calling a jQuery in your loading function, thus first way is probably better)

Add it via the JSAPI Google Loader you're using:

<head>      
    <script type='text/javascript' src='http://www.google./jsapi'></script>
    <script type='text/javascript'>
        google.load('visualization', '1', {'packages':['annotatedtimeline']});
        google.load("jquery", "1.8.3"); // note, you can also load jQueryUI this way,

// on another note, not sure how high a version google supports
Please see Hosted Libs for more info

发布评论

评论列表(0)

  1. 暂无评论