how i get response data and status header from json with axios?
whats wrong with my axios code?
my constructor:
class DetailProduct extends React.Component{
constructor(){
super();
this.state = {
dataOperations: [],
isLoading: true
};
console.log(this.state.idf)
axios.post('http://127.0.0.1:8000/barang/select/', { id: 1 })
.then(function(response){
console.log(response.data)
console.log(response.status)
});
}
my Django rest framework:
class Selectitem(GenericAPIView):
permission_classes = []
def post(self, request):
getb = Barang.objects.filter(pk = request.POST.get('id'))
if getb.exists():
f = getb.first()
return Response({'nama_barang': f.nm_barang, 'harga_satuan': f.harga_satuan}, status=status.HTTP_200_OK)
else:
return Response({"message": "What you were looking for isn't here."}, status=status.HTTP_400_BAD_REQUEST)
def get_serializer_class(self):
return SelectItem
i can get data if using postman