0

i have a problem with the scope of my variable and i dont know what i'm doing wrong! I would like to get a file path out of the ajax success scope but it doesnt work. Do anybody have a glue what where my mistakes are.

Regards!

            var uploadPathPicture;
            var uploadPictureFileData           = $('#profilbild').prop('files')[0];
            var uploadPictureFileDataFormData   = new FormData();

            uploadPictureFileDataFormData.append('file', uploadPictureFileData);
            uploadPictureFileDataFormData.append('mail', $('#mail').val());

            $.ajax({
                type: 'POST',
                url: '../php/uploadPicture.php',
                data: uploadPictureFileDataFormData,
                dataType: 'text',
                cache: false,
                processData: false,
                contentType: false,
                success: function(result)
                {
                    //uploadPathPicture = result;
                    uploadPathPicture = "huhu";
                    console.log(uploadPathPicture);
                }
            });

            alert(uploadPathPicture);
  • The `ajax` call is happen **after** the `alert` that you have in the last line, so the first alert you get is undefined, and only after that alert you will get the alert inside the `success` function of the ajax call. – Dekel Nov 09 '16 at 14:40
  • @freedomn-m nope - OP isn't returning a value. – Rory McCrossan Nov 09 '16 at 14:42

0 Answers0