我创建了一个简单的表单来通过 API 返回翻译键列表。但它说 Uncaught SyntaxError: Unexpected token :
这是我的示例代码。
我的表格:
<form id="upload_form">
<button type="submit">Ajax Request</button>
</form>
我的ajax调用:
$("#upload_form").submit(function(e){
e.preventDefault();
$.ajax({
url:'https://lokali.se/api/string/list',
data:'api_token=641bc8455768b09589806c7d489640789cfb49e1&id=7509115157679787966292.60209031',
dataType:'jsonp',
type:'post',
contentType: 'application/x-www-form-urlencoded',
success:function(response){
console.log('hi');
console.log(response);
},
});
});
当我通过 postman 测试 API 时,它返回 Success OK 200 响应 作为引用,请找到屏幕截图
我的错误来自这里{"response":{"status":"error","code":4049,"message":"缺少请求参数"}}
任何人都可以帮助我在这里?
最佳答案
你可以尝试像下面这样吗?
$("#upload_form").submit(function(e){
e.preventDefault();
var envelope = {};
envelope.api_token = '641bc8455768b09589806c7d489640789cfb49e1';
envelope.id='7509115157679787966292.60209031';
$.ajax({
url:'https://lokali.se/api/string/list',
data:envelope,
dataType:'json',
type:'post',
contentType: 'application/x-www-form-urlencoded',
success:function(response){
console.log('hi');
console.log(response);
},
});
});
关于javascript - 未捕获的语法错误 : Unexpected token : AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38077658/