can’t upload Image with ajax jquery.
-
Please, if anyone can point me in the right direction. I wish to upload an image to my ACF image field. I can successfully post to text and number fields but not to the image fields. Sorry, if there is an obvious answer I haven’t found. I am a bit new to it.
let frmData = new FormData(); let imageData = { status: "publish", "fields[image]": $("#file")[0].files[0], }; for (let key in imageData) { frmData.append(key, imageData[key]); } $.ajax({ method: "PATCH", url: siteData._siteURL + "/house/" + theID, beforeSend: function (xhr) { xhr.setRequestHeader("X-WP-Nonce", siteData.nonce); }, contentType: false, processData: false, data: frmData , success: function (res) { console.log(res); }, error: function (jqXhr, textStatus, error) { console.log("error happened!"); }, });
- The topic ‘can’t upload Image with ajax jquery.’ is closed to new replies.