
I tried $_POST and file_get_contents("php://input") in PHP, sending from axios with FormData or using a json construct, but I can never get both the file upload and the input fields. Problem is axios is giving me some headaches with PHP on the other side, when posting both normal input fields and uploading a file in the same form. I've used axios for dart/flutter but now I'm learning react for building my web sites, and JQuery doesn't make sense. In the more classic workflow (HTML/PHP/JQuery) I've used $.ajax() in the client and PHP on the server with total success. To get the json object response: in fetch call the json() function on the response object, in Axios get data property of the response object.Ī job I do a lot it seems, it's to send forms via ajax, that usually includes an attachment and several input fields.Fetch request is ok when response object contains the ok property, Axios request is ok when status is 200 and statusText is 'OK'.Fetch request function includes the url as parameter, Axios request function does not include the url as parameter.Fetch has no url in request object, Axios has url in request object.Fetch's body has to be stringified, Axios' data contains the object.Let responseOK = response & response.status = 200 & response.statusText = 'OK'


Let response = await fetch(url, options) 'Content-Type': 'application/json charset=UTF-8' Fetch and Axios are very similar in functionality, but for more backwards compatibility Axios seems to work better (fetch doesn't work in IE 11 for example, check this post)Īlso, if you work with JSON requests, the following are some differences I stumbled upon with.
