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);
}
});
});
Bhavin Gohil
5113 silver badges9 bronze badges
asked Dec 13, 2021 at 18:19
Rafael Fagundes
4454 silver badges17 bronze badges
-
Try your luck: magento.stackexchange.com/a/265492/77554 Let me know if it work or notNilesh Dubey– Nilesh Dubey2021年12月14日 06:58:46 +00:00Commented Dec 14, 2021 at 6:58
-
@NileshDubey, i answered the question, take a look.Rafael Fagundes– Rafael Fagundes2021年12月14日 13:28:34 +00:00Commented Dec 14, 2021 at 13:28
1 Answer 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
Rafael Fagundes
4454 silver badges17 bronze badges
default