Javascript AdonisJS-SyntaxError。意外字符“”
我试图从数据库中获取所有人才资源,但当我在Postman上尝试端点时,它返回了一个语法错误。意外的字符错误。我不知道这个字符是从哪里来的,因为邮递员暗示错误在我控制器的第66行,但在检查时,第66行是空行/空行。 什么可能导致此错误? 我的控制器代码API调用的方法如下Javascript AdonisJS-SyntaxError。意外字符“”,javascript,laravel,api,laravel-5,adonis.js,Javascript,Laravel,Api,Laravel 5,Adonis.js,我试图从数据库中获取所有人才资源,但当我在Postman上尝试端点时,它返回了一个语法错误。意外的字符错误。我不知道这个字符是从哪里来的,因为邮递员暗示错误在我控制器的第66行,但在检查时,第66行是空行/空行。 什么可能导致此错误? 我的控制器代码API调用的方法如下 async searchTalent({ request, response }) { try { const params = request.except('projectId');
async searchTalent({ request, response }) {
try {
const params = request.except('projectId');
let matchedTalents = [];
let talentIds = [];
const {tools, fullname} = params;
if(tools) {
const find = await Database.raw("SELECT * FROM pro WHERE MATCH tools AGAINST ('"+ tools +"' IN NATURAL LANGUAGE MODE)");
const talents = find[0];
if(talents) {
for(let t = 0; t < talents.length; t++) {
const talent = talents[t];
if(talent.active == true) {
const user = await User.query().where({id: talent.userId, active: true, type: 'talent', isDeleted: false}).first();
if(user) {
if(talentIds.length > 0) {
if(talentIds.includes(talent.id) === false) {
user.profile = talent;
talentIds.push(talent.id);
matchedTalents.push(user);
}
} else {
user.profile = talent;
talentIds.push(talent.id);
matchedTalents.push(user);
}
}
}
}
}
// for (let i = 0; i < tools.length; i++) {
// const tool = tools[i];
// }
} else if(fullname) {
const getUsers = await User.query().where('first_name', 'LIKE', '%%' + fullname + '%%').orWhere('last_name', 'LIKE', '%%' + fullname + '%%').where({ active: true}).orderBy('id', 'desc').get();
for (let i = 0; i < getUsers.length; i++) {
const user = getUsers[i];
if(user.type == 'talent')
{
const talent = await Pro.query().where({userId: user.id}).first();
if(talent)
{
user.profile = talent;
matchedTalents.push(user);
}
}
}
}
const data = matchedTalents;
return response.json({
data: data,
message: data.length + ' Talents fetched',
error: false
})
} catch (e) {
Event.fire('log::error', e.message)
return response.json({
data: [],
message: e.message,
error: true
})
}
}
我从昨天开始尝试搜索和修复,但所有的stackoverflow答案似乎都没有解决此问题。在第53行和第55行看似空的行中,行首有\u200b字符。删除这些行上的第一个字符。看到这里的人物了。谢谢@Teemu,我尝试了你的答案,第一次尝试就成功了。非常感谢。起初我不知道什么是u200的字符,所以我做了一个小谷歌搜索,其中一个条目建议删除空白行,保存文件,并重新添加空白-我做了,问题得到解决。顺便问一下,你是怎么想出来的?因为我已经盯着代码看了很长时间,没有发现。有什么特殊的工具吗?通常,如果错误消息中的字符看起来是空的,实际上有一个不可见的字符。一些文本编辑器使用JSFIDLE使用的字形显示这些字符,然后,根据编辑器的不同,可能会有一个工具提示告诉字符的名称,或者您可以复制字符,并将其粘贴到类似的转换器,然后查看剪贴板上的实际内容。谢谢@Teemu,现在,我如何将您的答案标记为正确?