在代码中找不到语法错误
Can't find syntax error in code
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>
您的
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.");
}
});
为什么成功:函数(结果){} 为空?希望结果应该只能在成功功能上访问。
试试这个
$.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.");
}
});
相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- Javascript未捕获语法错误意外的标识符错误
- 为什么忽略了eval()代码中的语法错误
- 难以访问的JS环境中的语法错误
- 未捕获的语法错误:意外的标记{
- "未捕获的语法错误:意外的标记}"
- 未捕获的语法错误:无法在“文档”上执行“查询选择器”
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- $(input[]).仅在firefox中出现每个抛出语法错误
- 为什么浏览器没有为语法错误抛出异常
- 错误:语法错误,无法识别的表达式:不支持的伪:无效/RectJS/Unit Testing
- 未捕获的语法错误:意外的令牌,
- jQuery.getJSON失败,语法错误
- "未捕获的语法错误:意外的标记"角度JS
- 参数列表Three.js之后的未捕获语法错误:缺少)
- 循环的Javascript冻结浏览器,没有语法错误
- 为什么匿名函数本身就是javascript中的语法错误
- 这怎么不是语法错误?这毫无意义!(javascript)
- 语法错误:缺少:在属性 ID 之后
- 未捕获错误:语法错误,无法识别的表达式:input[@type=submit]