SyntaxError:missing;在声明Jquery之前

时间:2013-09-15 11:13:24

标签: javascript jquery syntax-error

我有一个javascript文件(从带有javascript标头的php动态生成)。 现在这段代码导致错误,我试图调试很长一段时间没有线索:

错误: SyntaxError:missing;在陈述之前

document.write('$(function() '+
   '{ $("#verify").click(function() '+
   '{var order = ""; '+
   '$(".captchaimage").each(function() '+
   '{order += "ggggg"+ $(this).attr("name");}) '+
   'console.log(order); '+
   '$.ajax({ '+
   'url: "http://healtheworld.com/own/json.php?var=" + order.substring(5), '+
   'dataType: "text", '+
   'cache: false, '+
   'success: function(data){console.log(data);} }); '+
   '}); '+
   '});'); 

2 个答案:

答案 0 :(得分:1)

;在这里遗失:

'{order += "ggggg"+ $(this).attr("name");}) '+

最后你需要它:

'{order += "ggggg"+ $(this).attr("name");}) ; '+

但它真的不是很好的编码风格; - )

答案 1 :(得分:1)

你为什么要这样做?如果PHP生成它,请将其放在<script></script>内,而不是像这样。

<script>
$(function(){ 
   $("#verify").click(function() {
      var order = "";
   $(".captchaimage").each(function(){
      order += "ggggg"+ $(this).attr("name");
   }) 
   console.log(order); 
   $.ajax({
      url: "http://healtheworld.com/own/json.php?var=" + order.substring(5), 
      dataType: "text", 
      cache: false, 
      success: function(data){console.log(data);} }); 
   }); 
});
</script>