Xhr.send : PDF upload failed with status 400 and response 0
-
Hello,
Hope you are doing good.I need your help if you may, please.
I have a js code that actually generate a pdf client side and should supposely upload it on the wordpress server. It’s not the first time i do that. It usually work, and the exact very same code work on another wordpress web-site i have. But for some reason, doesn’t work this time.
Both of the server are astra theme also, i don’t know if it help but still it won’t work this time and i don’t know why. The code is pretty simple :`const currentDate = new Date(); const dateFormat = ${("0" + (currentDate.getMonth()+1)).slice(-2)}/${("0" + currentDate.getDate()).slice(-2)} - ${("0" + currentDate.getHours()).slice(-2)}h${("0" + currentDate.getMinutes()).slice(-2)}; const xhr = new XMLHttpRequest(); xhr.open("POST", "https://eima.school/wp-admin/admin-ajax.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");` xhr.onreadystatechange = function() { if (xhr.readyState === 4) { if (xhr.status === 200) { console.log("PDF uploaded successfully"); aenvoyer[1].save(
${aenvoyer[2]} - ${aenvoyer[3]} - Inscription - Stages - EIMA - 2023 - ${dateFormat}.pdf
); event.target.submit(); } else { alert("PDF upload failed with status " + xhr.status + " and response " + xhr.responseText); } } }; aenvoyer[1].save(${aenvoyer[2]} - ${aenvoyer[3]} - Inscription - Stages - EIMA - 2023 - ${dateFormat}.pdf
); xhr.send(action=upload_pdf&pdfBase64=${encodeURIComponent(aenvoyer[0])}&nom=${encodeURIComponent(aenvoyer[2])}&prenom=${encodeURIComponent(aenvoyer[3])}
);I actually put the xhr.send two time voluntarily just to see if the pdf would download and it does perfectly. The only problem is it doesn’t upload anything on the server side with the error : PDF upload failed with status 400 and response 0.
Can someone help ? I have no idea what is actually happening.
I would suppose that something is going wrong in the admin-ajax, maybe the post method ? I don’t know how to check it or what to do. Usually when i code things like that it just work so…Thanks all for your help
- The topic ‘Xhr.send : PDF upload failed with status 400 and response 0’ is closed to new replies.