2016-04-27 9 views
0

Chromeデベロッパーツールは3行目にエラーがありますが、わかりません。確かに私はjQueryでコーディングするのが初めてであるので、私が従ったチュートリアルには何か問題があった可能性があります。コード内に構文エラーが見つかりません

$.ajax({ 
    url: 'https://www.carcraft.atsbusinessandgames.com/xmls/carcraft_1-7-10Test.xml', 
    type: "Get", 
    dataType: 'xml', 
    success: function (result) { 
     } 
     $(result).find('Module').each(function() { 
      //$("#ModsList").append($(this).text()); 
      var authors = $(this).find('authors').text(); 
      var version = $(this).find('version').text(); 
      var date = $(this).find('date').text(); 
      var episode = $(this).find('episode').text(); 
      $("#ModsList").append("<tr>" + "<td>" + $authors + "</td>" + "<td>" + $version + "</td>" + "<td>" + $date + "</td>" + "<td>" + $episode + "</td>" + "</tr>"); 
     }); 
    error: function() { 
    alert("Notify the site owner that the xml file has a syntax error and is therefore unreadable."); 
    } 
}); 

これは私が上記のコードを経由して変更しようとしているテーブルです:

<table id="ModsList"> 

    <tr style="font-weight: bold;"> 

     <td>Mod Name</td> 

     <td>Author(s)</td> 

     <td>Version</td> 

     <td>Date added/updated</td> 

     <td>Episode Added</td> 

    </tr> 

</table> 
+1

この行は3行ですか?また、 'authors'しかないときに' $ authors'を使うのはなぜですか? – guradio

+0

あなたが得ているエラーを投稿してください –

+0

あなたの成功のコールバックは間違って閉じられています。 – hmd

答えて

1

を試してみてください。あなたはsuccess関数のために{ }の間にコードを入れなければなりません。今のように、オブジェクト定義にランダムなコードを挿入していますが、これは合法ではありません。

変更はこれにコード:

$.ajax({ 
    url: 'https://www.carcraft.atsbusinessandgames.com/xmls/carcraft_1-7-10Test.xml', 
    type: "Get", 
    dataType: 'xml', 
    success: function (result) { 
     $(result).find('Module').each(function() { 
      //$("#ModsList").append($(this).text()); 
      var authors = $(this).find('authors').text(); 
      var version = $(this).find('version').text(); 
      var date = $(this).find('date').text(); 
      var episode = $(this).find('episode').text(); 
      $("#ModsList").append("<tr>" + "<td>" + authors + "</td>" + "<td>" + version + "</td>" + "<td>" + date + "</td>" + "<td>"+episode+"</td>" + "</tr>"); 
     }); 
    }, 
    error: function() { 
     alert("Notify the site owner that the xml file has a syntax error and is therefore unreadable."); 
    } 
}); 
0

はあなたのsuccessハンドラが適切に宣言されていないこの

$.ajax({ 
    url: 'https://www.carcraft.atsbusinessandgames.com/xmls/carcraft_1-7-10Test.xml', 
    type: "Get", 
    dataType: 'xml', 
    success: function (result) { 

     $(result).find('Module').each(function() { 
      //$("#ModsList").append($(this).text()); 
      var authors = $(this).find('authors').text(); 
      var version = $(this).find('version').text(); 
      var date = $(this).find('date').text(); 
      var episode = $(this).find('episode').text(); 
      $("#ModsList").append("<tr>" + "<td>" +authors+ "</td>" + "<td>" +version+ "</td>" + "<td>" +date +"</td>" + "<td>" +episode+ "</td>" + "</tr>"); 
     }); 
}, 
    failure: function() { 
    alert("Notify the site owner that the xml file has a syntax error and is therefore unreadable."); 
    } 
}); 
0

なぜ成功:関数(結果){}は空ですか?結果が成功関数でのみアクセス可能であることを望む。

関連する問題