【问题标题】:syntax error codepen full view语法错误codepen完整视图
【发布时间】:2017-02-23 08:40:39
【问题描述】:

我正在尝试完成对 freecodecamp 的维基百科搜索,(在 codepen 中),我遇到了这个问题,我的代码将在 codepen 的编辑视图和调试视图中运行,但无法运行,“详细信息视图”和“全视图”。控制台中给出的详细信息和完整视图中的错误是,

"Uncaught SyntaxError: missing ) after argument list"

,但是 jshint 似乎找不到错误,否则代码似乎运行良好?它只是一个代码笔错误吗?

这是我的笔。很粗略。 :o

https://codepen.io/ohrha/pen/wgZYvM?editors=1000(编辑器视图)(工作) https://codepen.io/ohrha/full/wgZYvM/(全视图)(不工作)

    $.ajax ({
              type:'GET',
              url: prefixSearch,
              dataType:'jsonp',
              success: function(jason){
                     var prefixSearchResults= jason;
                     console.log(prefixSearchResults.query.prefixsearch.length);
                     console.log(prefixSearchResults.query.prefixsearch[0].pageid);
                     console.log(prefixSearchResults.query.prefixsearch[0].title);


                     for(var i= 0; i<prefixSearchResults.query.prefixsearch.length;i++){
                     curid.push( "https://crossorigin.me/https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exchars=175&explaintext&pageids="+prefixSearchResults.query.prefixsearch[i].pageid);  queryResultsArray.push(prefixSearchResults.query.prefixsearch[i].pageid);
               queryResultUrls.push("<a rel="nofollow" rel="noreferrer"href= 'https://en.wikipedia.org/?curid="+prefixSearchResults.query.prefixsearch[i].pageid+">"+prefixSearchResults.query.prefixsearch[i].title+"</a><br>"+prefixSearchResults); 

//here the "Uncaught SyntaxError: missing ) after argument list" error occurs.
                       extracts.push(prefixSearchResults.query.prefixsearch[i].pageid);
                       console.log(extracts);
                     }
                     }}); 

有什么想法吗?

【问题讨论】:

  • 你的引用在你的queryResultUrls.push( here ) 中混淆了"'
  • 啊,谢谢。我可以不使用组合吗?还是逃避我唯一的选择?
  • 组合很好。如果以" " 开始和结束标记,则可以在内部使用' ',反之亦然,如果以' ' 开始和结束,则可以使用" " insde

标签: javascript jquery html css


【解决方案1】:

@subwaymatch 指出的转义引号的替代方法,您可以在此处使用单引号

queryResultHrefLink='<a href="https://en.wikipedia.org/?curid='+prefixSearchResults.query.prefixsearch[i].pageid+'">'+prefixSearchResults.query.prefixsearch[i].title+'</a><br>'+prefixSearchResults;

【讨论】:

  • 完美运行!谢谢!
  • @trigramthree 太棒了,不客气 :) *pound*
【解决方案2】:

您需要转义 queryResultUrls.push() 中的 "(双引号)。

queryResultUrls.push("<a rel=\"nofollow\" rel=\"noreferrer\" href= 'https://en.wikipedia.org/?curid="+prefixSearchResults.query.prefixsearch[i].pageid+">"+prefixSearchResults.query.prefixsearch[i].title+"</a><br>"+prefixSearchResults);

【讨论】:

  • 是的,这是我对单引号和双引号的不当使用以及纠正时双引号缺少转义的组合。 "rel="no follow" 和 rel="no referrer" 实际上只出现在我的控制台视图中,我不小心发布了那个版本。
猜你喜欢
  • 2012-05-13
  • 1970-01-01
  • 2017-06-29
  • 2020-07-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多