How to send input file data value using ajax to a php page

前端 未结 4 1096
有刺的猬
有刺的猬 2020-12-07 04:55

What I want to do is whenever a user selects a picture and click the button it will move the image to a specific folder and save the link to the database user_image column.<

4条回答
  •  遥遥无期
    2020-12-07 05:18

    Take a look at this http://malsup.com/jquery/form/#ajaxSubmit.

    Include that plugin jquery.form.js and then try this.

    $('#FormID').ajaxSubmit({ //FormID - id of the form.
            type: "POST",
            url: "Oppa/view/photo.php",
            data: $('#FormID').serialize(),
            cache: false,
            success: function (response) {
    
            if (Number(response) == 1)
                {
                   $("#dialog-confirm-changedImage").dialog("open");
                }
            }
        });
    

    This should work. I'm using it for ajax image upload.

    Thanks.

提交回复
热议问题