0

I implemented form and I need to send Image to PHP function.. but is does not work. Did I implement correct selector for my picture?

var photoAdvertisement = $("#pro-img-4").attr('src');
    // get values to an array()
    var requestArray = "";

    requestArray = {"name" : $("#nameAdvertisement").val(),
    "category" : $("#categoryAdvertisement").val(),
    "description" : $("#descriptionAdvertisement").val(),
    "photoAdvertisement" : $("#pro-img-4").attr('src')};


    $.ajax({
        url: ajaxurl,
        type: "POST",
        data: {"action": "addAdvertisement", "formValidation": requestArray},
        //dataType: "html",
        success: function (data) {

            console.log("data: "+data);
        }
    });

Picture of my HTML class and ID with picture

enter image description here

It returned me long string in similar like that => data:image/jpeg;base64,/9j/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdCIFhZWiAH3A . Please, is that correct way ?

Matus Vrsansky
  • 83
  • 1
  • 10
  • A base64-encoded image that starts with `data:image` in the `src` attribute should render correctly. – Obsidian Age Jan 23 '19 at 21:36
  • " but is does not work" What does not work exactly? You are reading the attribute and it is giving you the base64 code, is it having issues with the post? – epascarello Jan 23 '19 at 21:38
  • that Image String is send to PHP for adding picture to My Post in Wordpress, do I have to parse that incoming long string to the some different way? Or this string is correct and should cause adding picture ? – Matus Vrsansky Jan 23 '19 at 21:44
  • Check out these answers: https://stackoverflow.com/questions/48867591/post-sending-base64-image-with-ajax and https://stackoverflow.com/questions/44599205/how-to-send-base64-image-via-ajax https://stackoverflow.com/questions/34047648/how-to-post-an-image-in-base64-encoding-via-ajax – Hektor Jan 23 '19 at 21:56

0 Answers0