Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sending multiple data ajax

I want to send the data which is in the variable "blog_id" to the page "blog_img_upload.php" along with the "form_data"
Please help.
The codes are in below –


var blog_id = "<?php echo"$blog_id"?>";
let form_data = new FormData();
let img = $("#myImage")[0].files;
 
          if(img.length > 0){
          form_data.append('my_image', img[0]);
          $.ajax({
            url: 'blog_img_upload.php',
            type: 'post',
            data: form_data,
            //data:{ form_data, blog_id: blog_id }, // can I do like this ?
            contentType: false,
                processData: false,
                success: function(res){
                  const data = JSON.parse(res);
                  if (data.error != 1) {
                       let path = "../ui/images/blog_images/"+data.src;
                       $("#preImg").attr("src", path);
                       $("#preImg").fadeOut(1).fadeIn(1000);
                       $("#myImage").val('');
                  }else {
                    $("#errorMs").text(data.em);
                  }
                  $('#img_main_show_div').load(location.href + " #img_main_show_div");
                }
          });
         
        }


>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

form_data.append('my_image', img[0]);
form_data.append('blog_id', '<?php echo blog_id; ?>');
.
.
.
//ajax 
data: form_data
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading