2016-04-27 54 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

试试这个

$.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

为什么成功:函数(结果){}正在空的?希望结果只能在成功函数中访问。