javascript - Expected an identifier and instead saw '<' - Stack Overflow

I get this error at the very beginning. Not sure how to fix. I also get the expected an assignment or f

I get this error at the very beginning. Not sure how to fix. I also get the expected an assignment or function call and instead saw an expression. Not to mention Expected an identifier and instead saw "var"

<script>
var interactiveSearch = {};
(function() {
  interactiveSearchmon = {
    init: function() {
      interactiveSearchmon.setupDataTableDefaults();
      $.ajaxSetup({
        cache: false
      });
    },
    setupDataTableDefaults: function() {
      $.extend($.fn.dataTable.defaults, {
        "sDom": "<'table-header-controls'<'row'<l><f>>r><i>t<'table-footer-controls'<'row'<'span12'p><'span12'i>>>",
        "sPaginationType": "bootstrap",
        "bJQueryUI": false,
        "bProcessing": false,
        "bServerSide": true,
        "fnServerData": interactiveSearchmon.getTableData
      });
    },
    getTableData: function(sSource, aoData, fnCallback) {
      var data = new Array();
      var columnCount = _.find(aoData, function(o) {
        return o.name == 'iColumns';
      }).value;
      var echo = _.find(aoData, function(o) {
        return o.name == 'sEcho';
      }).value;
      var skip = _.find(aoData, function(o) {
        return o.name == 'iDisplayStart';
      }).value;
      var take = _.find(aoData, function(o) {
        return o.name == 'iDisplayLength';
      }).value;
      var search = _.find(aoData, function(o) {
        return o.name == 'sSearch';
      }).value;
      var sortCols = _.filter(aoData, function(o) {
        return o.name.indexOf('iSortCol_') == 0;
      });
      var sortDirs = _.filter(aoData, function(o) {
        return o.name.indexOf('sSortDir_') == 0;
      });
      var searches = _.filter(aoData, function(o) {
        return o.name.indexOf('sSearch_') == 0;
      });
      data.push({
        "name": "TableEcho",
        "value": echo
      });
      data.push({
        "name": "Skip",
        "value": skip
      });
      data.push({
        "name": "Take",
        "value": take
      });
      data.push({
        "name": "AllSearch",
        "value": search
      });
      var actual = 0;
      _.each(sortCols, function(columnSort, sortIndex) {
        var columnIndex = columnSort.value;
        var columnSearch = searches[columnIndex].value;
        var sortDir = sortDirs[sortIndex].value;
        data.push({
          "name": "Columns[" + actual + "].ColumnIndex",
          "value": columnIndex
        });
        data.push({
          "name": "Columns[" + actual + "].SortDirection",
          "value": sortDir
        });
        if (columnSearch != '') {
          data.push({
            "name": "Columns[" + actual + "].SearchTerm",
            "value": columnSearch
          });
        }
        actual++;
      });
      for (var i = 0; i < columnCount; i++) {
        var searchTerm = searches[i].value;
        if (searchTerm == '') {
          continue;
        }
        data.push({
          "name": "Columns[" + actual + "].ColumnIndex",
          "value": i
        });
        data.push({
          "name": "Columns[" + actual + "].SearchTerm",
          "value": searchTerm
        });
        actual++;
      }
      $.post(sSource, data)
        .success(fnCallback);
    }
  };
})();
$(function() {
  interactiveSearchmon.init();
});
(function() {
  var product = interactiveSearch.product = {};
  product.init = function() {
    product.initDataTable();
    product.bindEvents();
  };

  function convertFullRowToDataObject(fullRow) {
    return {
      Id: fullRow[0],
      ProductName: fullRow[1],
      Synonym: fullRow[2],
      Acronym: fullRow[3],
      CasNo: fullRow[4],
      EinecsNo: fullRow[5],
      Formula: fullRow[6],
      MolecularWeight: fullRow[7],
      Status: fullRow[8],
      MeltingPoint: fullRow[9],
      BoilingPoint: fullRow[10],
      HasDoc: fullRow[11] !== '',
      RelatedDocPath: product.baseUrl + fullRow[11],
      HasDImage: fullRow[12] !== '',
      ImagePath: product.baseUrl + fullRow[12]
    };
  }
  product.initDataTable = function() {
    product.productTable = $("#product-table").dataTable({
      aaSorting: [
        [1, "asc"]
      ],
      iDisplayLength: 15,
      bServerSide: true,
      bDestroy: true,
      sAjaxSource: interactiveSearch.product.listUrl,
      fnRowCallback: function(nRow, aData) {
        $(nRow).data('rowInfo', convertFullRowToDataObject(aData));
      },
      aoColumns: [{
        sType: "string",
        sClass: "dtAlignLeft",
        mData: 1
      }]
    });
  };
  product.bindEvents = function() {
    _.templateSettings = {
      interpolate: /\{\{(.+?)\}\}/g,
      evaluate: /\{\[([\s\S]+?)\]\}/g
    };
    var templateText = $('#productDetailTemplate').html(),
      piledTemplate = _.template(templateText);
    $(document).on('click', '#product-table tr', function(e) {
      var el = $(this);
      var rowData = el.data('rowInfo');
      var html = piledTemplate(rowData);
      $('#productDetailContainer').empty().html(html);
      $('#product-table tr').removeClass('active');
      el.addClass('active');
    });
    $('#searchClone').on('keyup', function(e) {
      var el = $(this);
      var mimicEl = $('#product-table_filter input');
      mimicEl.val(el.val()).trigger('keyup');
    })
    $('.btn-reset-filter').on('click', function() {
      $('#searchClone').val('').trigger('keyup');
    });
  };
})();
$(document).ready(function() {
  interactiveSearch.product.listUrl = '/pa/Product/ListItems';
  interactiveSearch.product.baseUrl = '/pa/';
  interactiveSearch.product.init();
});
</script>

I get this error at the very beginning. Not sure how to fix. I also get the expected an assignment or function call and instead saw an expression. Not to mention Expected an identifier and instead saw "var"

<script>
var interactiveSearch = {};
(function() {
  interactiveSearch.mon = {
    init: function() {
      interactiveSearch.mon.setupDataTableDefaults();
      $.ajaxSetup({
        cache: false
      });
    },
    setupDataTableDefaults: function() {
      $.extend($.fn.dataTable.defaults, {
        "sDom": "<'table-header-controls'<'row'<l><f>>r><i>t<'table-footer-controls'<'row'<'span12'p><'span12'i>>>",
        "sPaginationType": "bootstrap",
        "bJQueryUI": false,
        "bProcessing": false,
        "bServerSide": true,
        "fnServerData": interactiveSearch.mon.getTableData
      });
    },
    getTableData: function(sSource, aoData, fnCallback) {
      var data = new Array();
      var columnCount = _.find(aoData, function(o) {
        return o.name == 'iColumns';
      }).value;
      var echo = _.find(aoData, function(o) {
        return o.name == 'sEcho';
      }).value;
      var skip = _.find(aoData, function(o) {
        return o.name == 'iDisplayStart';
      }).value;
      var take = _.find(aoData, function(o) {
        return o.name == 'iDisplayLength';
      }).value;
      var search = _.find(aoData, function(o) {
        return o.name == 'sSearch';
      }).value;
      var sortCols = _.filter(aoData, function(o) {
        return o.name.indexOf('iSortCol_') == 0;
      });
      var sortDirs = _.filter(aoData, function(o) {
        return o.name.indexOf('sSortDir_') == 0;
      });
      var searches = _.filter(aoData, function(o) {
        return o.name.indexOf('sSearch_') == 0;
      });
      data.push({
        "name": "TableEcho",
        "value": echo
      });
      data.push({
        "name": "Skip",
        "value": skip
      });
      data.push({
        "name": "Take",
        "value": take
      });
      data.push({
        "name": "AllSearch",
        "value": search
      });
      var actual = 0;
      _.each(sortCols, function(columnSort, sortIndex) {
        var columnIndex = columnSort.value;
        var columnSearch = searches[columnIndex].value;
        var sortDir = sortDirs[sortIndex].value;
        data.push({
          "name": "Columns[" + actual + "].ColumnIndex",
          "value": columnIndex
        });
        data.push({
          "name": "Columns[" + actual + "].SortDirection",
          "value": sortDir
        });
        if (columnSearch != '') {
          data.push({
            "name": "Columns[" + actual + "].SearchTerm",
            "value": columnSearch
          });
        }
        actual++;
      });
      for (var i = 0; i < columnCount; i++) {
        var searchTerm = searches[i].value;
        if (searchTerm == '') {
          continue;
        }
        data.push({
          "name": "Columns[" + actual + "].ColumnIndex",
          "value": i
        });
        data.push({
          "name": "Columns[" + actual + "].SearchTerm",
          "value": searchTerm
        });
        actual++;
      }
      $.post(sSource, data)
        .success(fnCallback);
    }
  };
})();
$(function() {
  interactiveSearch.mon.init();
});
(function() {
  var product = interactiveSearch.product = {};
  product.init = function() {
    product.initDataTable();
    product.bindEvents();
  };

  function convertFullRowToDataObject(fullRow) {
    return {
      Id: fullRow[0],
      ProductName: fullRow[1],
      Synonym: fullRow[2],
      Acronym: fullRow[3],
      CasNo: fullRow[4],
      EinecsNo: fullRow[5],
      Formula: fullRow[6],
      MolecularWeight: fullRow[7],
      Status: fullRow[8],
      MeltingPoint: fullRow[9],
      BoilingPoint: fullRow[10],
      HasDoc: fullRow[11] !== '',
      RelatedDocPath: product.baseUrl + fullRow[11],
      HasDImage: fullRow[12] !== '',
      ImagePath: product.baseUrl + fullRow[12]
    };
  }
  product.initDataTable = function() {
    product.productTable = $("#product-table").dataTable({
      aaSorting: [
        [1, "asc"]
      ],
      iDisplayLength: 15,
      bServerSide: true,
      bDestroy: true,
      sAjaxSource: interactiveSearch.product.listUrl,
      fnRowCallback: function(nRow, aData) {
        $(nRow).data('rowInfo', convertFullRowToDataObject(aData));
      },
      aoColumns: [{
        sType: "string",
        sClass: "dtAlignLeft",
        mData: 1
      }]
    });
  };
  product.bindEvents = function() {
    _.templateSettings = {
      interpolate: /\{\{(.+?)\}\}/g,
      evaluate: /\{\[([\s\S]+?)\]\}/g
    };
    var templateText = $('#productDetailTemplate').html(),
      piledTemplate = _.template(templateText);
    $(document).on('click', '#product-table tr', function(e) {
      var el = $(this);
      var rowData = el.data('rowInfo');
      var html = piledTemplate(rowData);
      $('#productDetailContainer').empty().html(html);
      $('#product-table tr').removeClass('active');
      el.addClass('active');
    });
    $('#searchClone').on('keyup', function(e) {
      var el = $(this);
      var mimicEl = $('#product-table_filter input');
      mimicEl.val(el.val()).trigger('keyup');
    })
    $('.btn-reset-filter').on('click', function() {
      $('#searchClone').val('').trigger('keyup');
    });
  };
})();
$(document).ready(function() {
  interactiveSearch.product.listUrl = '/pa/Product/ListItems';
  interactiveSearch.product.baseUrl = '/pa/';
  interactiveSearch.product.init();
});
</script>
Share Improve this question edited May 17, 2016 at 20:00 Mike Cluck 32.5k13 gold badges83 silver badges94 bronze badges asked May 17, 2016 at 19:59 gdeleon101gdeleon101 981 gold badge2 silver badges11 bronze badges 6
  • 2 Is all of this inside of a .js file? – Mike Cluck Commented May 17, 2016 at 20:00
  • On which line did you get said errors? – Robin-Hoodie Commented May 17, 2016 at 20:04
  • 2 If this is in a .js file, you should not have <script> and </script> around the code. That's only used when you embed Javascript in an HTML file. – Barmar Commented May 17, 2016 at 20:07
  • three on line 1, and one on line2 – gdeleon101 Commented May 17, 2016 at 20:09
  • 1 @gdeleon101 If that code is inside of an HTML file then that is not the offending code. All of that code is syntactically valid. – Mike Cluck Commented May 17, 2016 at 20:14
 |  Show 1 more ment

1 Answer 1

Reset to default 4

In .js files you don't have to put <script>, you can just write your code.

<script> is for HTML files when you have to insert a script in the middle of the page.

So you have to delete <script> and </script> in your file.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744256695a4565433.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信