Search code examples
jsonpostreactjsfetchisomorphic-fetch-api

isomorophic-fetch don't post json body


I have this code in my react app and it didn't post the json body ! have tried every solution even the one here https://github.com/matthew-andrews/isomorphic-fetch/issues/34 not working too , i can do the post with jquery , but i need to use fetch , any idea ?

fetch('/main/newuser',{
            method:'post',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body:JSON.stringify({username:'test',password:'test'})
        }).then((response)=>{
            if(response.status >= 200 && response.status < 300){
                return response;
            }else{
                var error = new Error(response.statusText);
                error.response = response;
                throw error;
            }
        }).then((response)=>{
            return response.json();
        }).then((data)=>{
            /* Process data */
        }).catch((error)=>{
            /* Catch Error */
        });

Solution

  • After tried everything possible ( edit code as sugguested , check the browser up to date and working , check the server code , the library work will with the GET method but POST still not working ) i switched back to our old and love JQuery !