weixin_33699914 2017-10-25 08:32 采纳率: 0%
浏览 297

PHP FormData为空

I have a form with id: formC, on submit i call ajax:

        var datiForm = new FormData();

        var pos = [];
        var i = 0;
        posizioni.each(function () {

            if($(this).find("input[type=checkbox]").is(":checked")){

                pos[i] = $(this).find("input[type=checkbox]").data("id");
                i++;
            }


        });

        datiForm.append("nome",nome.val());
        datiForm.append("cognome",cognome.val());
        datiForm.append("email",email.val());
        datiForm.append("telefono",telefono.val());
        datiForm.append("dataNascita",dataNascita.val());
        datiForm.append("titolo",titolo.val());
        datiForm.append("ruolo",ruolo.find(":selected").data("ruolo"));
        datiForm.append("sede",sede.find(":selected").data("sede"));
        datiForm.append("posizione",pos);
        datiForm.append("cvFile",$("#cvFile")[0].files[0]);

        $.ajax({

            type: "POST",
            data: {datiForm: datiForm},
            url: "saveCandidate.php",
            processData: false,
            contentType: false,
            success: function (data) {

                console.log(data);


            },
            error: function (data) {

                var position = data;


            }


        });

I have a problem, on server $datiForm = $_POST["datiForm"]; is null why? Moreover i have input file where i can select file pdf. I put it in FormData:

datiForm.append("cvFile",$("#cvFile")[0].files[0]);

Now on server i want to take file from $datiForm and save it into mysql as Blob is possible?

  • 写回答

2条回答 默认 最新

  • 狐狸.fox 2017-10-25 08:34
    关注

    You'll need to specify the 'contentType' attribute to 'multipart/form-data' in order to upload files.

    评论

报告相同问题?