简体   繁体   中英

Uncaught SyntaxError: Unexpected token : AJAX

I have created a simple form to return a list of translation keys through the API. But it says Uncaught SyntaxError: Unexpected token : Here is my sample code.

My form:

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

My ajax call:

$("#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 邮差

My error is from here {"response":{"status":"error","code":4049,"message":"Missing request parameter"}} Can anyone help me out here?

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); }, }); }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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