简体   繁体   English

未捕获到的SyntaxError:意外令牌:AJAX

[英]Uncaught SyntaxError: Unexpected token : AJAX

I have created a simple form to return a list of translation keys through the API. 我创建了一个简单的表单来通过API返回翻译键列表。 But it says Uncaught SyntaxError: Unexpected token : Here is my sample code. 但它显示Uncaught SyntaxError: Unexpected token :这是我的示例代码。

My form: 我的表格:

<form id="upload_form">
    <button type="submit">Ajax Request</button>
</form>

My ajax call: 我的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);      
    },
});    
});

When I tested the API through postman it returns the Success OK 200 response For reference please find the screenshot 当我通过邮递员测试API时,它返回Success OK 200响应作为参考,请找到屏幕截图 邮差

My error is from here {"response":{"status":"error","code":4049,"message":"Missing request parameter"}} Can anyone help me out here? 我的错误来自这里{"response":{"status":"error","code":4049,"message":"Missing request parameter"}}有人可以在这里帮助我吗?

Can you try like the following ? 您可以尝试以下方法吗?

 $("#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); }, }); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM