-1

私はjavascriptファイルを持っています(javascriptヘッダーを持つphpから動的に生成されます)。今、このコードはエラーになります。手がかりなしでかなり長い間デバッグしようとしました:

エラー: SyntaxError: がありません。ステートメントの前に

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);} }); '+
   '}); '+
   '});'); 
4

2 に答える 2

1

; ここにありません:

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

最後に必要です:

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

しかし、それは本当に良いコーディング スタイルではありません ;-)

于 2013-09-15T11:27:44.197 に答える
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>
于 2013-09-15T11:28:31.110 に答える