0

So what I am trying to do is do send some data by clicking a submit button (A mathematical expression) to a Django-API. There this expression is processed and a new expression is returned to another textbox. I am trying to do this in a single function. The Post requests are working perfectly fine which I have checked through the Postman application.

I am unable to fetch the processed data from the API. I am getting the following error --> GET http://127.0.0.1:8000/differentiate/ 405 (Method Not Allowed)

The overview of the application --> Overview

The code for my function is ->

async postData() {
        const url = 'http://127.0.0.1:8000/differentiate/';
        let result = await fetch(url,{
            method: 'post',
            mode: 'no-cors',
            headers: {
                'Accept': 'application/json',
                'Content-type': 'application/json',
            },
            body: JSON.stringify({
                functiondata: this.fx
            })
        }); 
        fetch(url).then(res => res.json()).then(json => {
            this.setState({
                fprimex: JSON.stringify(json)
            })
        }) 
        
    };
  • Does this answer your question? [How does Access-Control-Allow-Origin header work?](https://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work) – Ajeet Shah Feb 28 '21 at 12:53
  • Thank you. I fixed that and now another error has appeared. I've updated my post accordingly. Please see – Anuj Dhillon Feb 28 '21 at 14:24
  • **405 Method not allowed** means (in your case) server is not expecting a GET request, maybe POST or PUT. You need to check with your backend guy. – Ajeet Shah Feb 28 '21 at 14:25

0 Answers0