1

I'm trying to do an ajax API call on the admin page, but it returns a Decoding error: \nUnable to unserialize value. Error: Syntax error...

$('#button').on('click', function(){
 $.ajax({
 url: "<?php echo $block->getBaseUrl()."rest/V1/orders" ;?>",
 data: {
 "entity":{
 "entity_id": Number(<?php echo $order_id; ?>),
 "status":"processing",
 "state":"processing"
 }
 },
 type: 'POST',
 headers: {
 "Content-Type": "application/json",
 "Authorization": "Bearer "+"<?php echo $token; ?>"
 },
 success: function(response){
 console.log(response);
 },
 error: function (xhr, status, errorThrown) {
 console.log('Error happens. Try again.');
 console.log('xhr: ', xhr);
 console.log('status: ', status);
 console.log('errorThrown: ', errorThrown);
 }
 });
});
asked Dec 13, 2021 at 18:19
2
  • Try your luck: magento.stackexchange.com/a/265492/77554 Let me know if it work or not Commented Dec 14, 2021 at 6:58
  • @NileshDubey, i answered the question, take a look. Commented Dec 14, 2021 at 13:28

1 Answer 1

1

So i tried this way and worked:

var settings = {
 "url": "<?php echo $block->getBaseUrl()."rest/V1/orders" ;?>",
 "method": "POST",
 "timeout": 0,
 "headers": {
 "Content-Type": "application/json",
 "Authorization": "Bearer "+"<?php echo $token; ?>"
 },
 "data": JSON.stringify(
 {
 "entity":{
 "entity_id": order_id,
 "status":"processing",
 "state":"processing"
 }
 }
 ),
 }
 $.ajax(settings).done(function (response) {
 console.log(response);
 });
answered Dec 14, 2021 at 13:27
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.