Ajax Upload image

后端 未结 4 1053
失恋的感觉
失恋的感觉 2020-11-22 03:57

Q.1 I would like to convert this form to ajax but it seems like my ajax code lacks something. On submit doesn\'t do anything at all.

Q2. I also want the function to

4条回答
  •  名媛妹妹
    2020-11-22 04:18

    first in your ajax call include success & error function and then check if it gives you error or what?

    your code should be like this

    $(document).ready(function (e) {
        $('#imageUploadForm').on('submit',(function(e) {
            e.preventDefault();
            var formData = new FormData(this);
    
            $.ajax({
                type:'POST',
                url: $(this).attr('action'),
                data:formData,
                cache:false,
                contentType: false,
                processData: false,
                success:function(data){
                    console.log("success");
                    console.log(data);
                },
                error: function(data){
                    console.log("error");
                    console.log(data);
                }
            });
        }));
    
        $("#ImageBrowse").on("change", function() {
            $("#imageUploadForm").submit();
        });
    });
    

提交回复
热议问题