Jquery ReferenceError: (name der Funktion) nicht definiert ist

Habe ich in diesem code, dass mir stecken für die Tage, die ich nicht verstehe, warum sagt er in meine Konsole, mein Funktion ist nicht definiert, hier ist der code. übrigens, ich bin super neu auf jQuery ich habe nicht wirklich viel wissen, es also keine Hilfe? kann jemand mir sagen, wo ich ging schief, dass es mir dieser Fehler

(ReferenceError: createGraph ist nicht definiert)

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

        <script src="bin/js/raphael.js"></script>
        <script src="bin/js/popup.js"></script>
        <script src="bin/js/analytics.js"></script>
</head>
<body>

 <div class="action-button">
    <button id="1" value="1074">Button 1</button>
    <button id="2" value="1074">Button 2</button>
 </div>

  <div id="output"></div>

<script>
/////////////////////////////////////////////////////
//this script will check if the document is ready and will display data for button 1
     $(document).ready(function () {
    $("#1").trigger("click");
    });

    ///////////////////////////////////////////////////////////////////////////////////////
        $("button").click(function () {
          var attr = $(this).attr("id");
          var val = $(this).val();

          $.ajax({
          type: "POST",
          url: "bin/some.php",
          data: { lookbookID: val, type:attr  }
    }).done(function( html ) {
      $("#output").html(attr + ' - ' +  val + ' - ' + html );
        createGraph();

    });
});
</script>
</body>
</html>

und der JS-code

window.onload = function () {
    function getAnchors(p1x, p1y, p2x, p2y, p3x, p3y) {
        var l1 = (p2x - p1x) / 2,
            l2 = (p3x - p2x) / 2,
            a = Math.atan((p2x - p1x) / Math.abs(p2y - p1y)),
            b = Math.atan((p3x - p2x) / Math.abs(p2y - p3y));
        a = p1y < p2y ? Math.PI - a : a;
        b = p3y < p2y ? Math.PI - b : b;
        var alpha = Math.PI / 2 - ((a + b) % (Math.PI * 2)) / 2,
            dx1 = l1 * Math.sin(alpha + a),
            dy1 = l1 * Math.cos(alpha + a),
            dx2 = l2 * Math.sin(alpha + b),
            dy2 = l2 * Math.cos(alpha + b);
        return {
            x1: p2x - dx1,
            y1: p2y + dy1,
            x2: p2x + dx2,
            y2: p2y + dy2
    };
}

    function createGraph() {
       //Grab the data
       alert("i made it!");
        var labels = [],
            data = [];
        $("#data tfoot th").each(function () {
        labels.push($(this).html());
        });
        $("#data tbody td").each(function () {
            data.push($(this).html());
        });

     }
    };

Ich aktualisiert, sorry das ich ausgeschlossen, dass window.onload ich immer noch, dass die Referenz-Fehler aber wenn ich die Funktion außerhalb window.onload = function dann meine Funktion funktionieren würde, gibt es eine Möglichkeit, ich kann auf meine Funktion? Ich weiß nicht, was passieren wird, wenn ich entfernen Sie die Sprach-code aus windows.onload ich brauche Hilfe wieder 🙂

den link für die Funktion nur für den Fall, es würde helfen, https://github.com/ksylvest/raphael-analytics

  • Das ist nicht, wie die Funktionen definiert sind. Sie müssen lernen, grundlegende Javascript-syntax.
  • $(function createGraph()() { ist eine ziemlich krasse syntax-Fehler.
  • +1 Eben fix typo-Fehler.
  • danke Jungs, ich wusste nicht, ich hatte das $() lol epic fail trotzdem danke sehr!
Schreibe einen Kommentar