0

I need to submit my controller an image and some data, and I need that ajax wait for the processing of my data so that you can show in another page after the data save them in my database, but when I use async false it already falls ajax error in the property, any idea how to solve this?

my code :

var album;
$('#buttonNex').click(function () {
            var url = 'NextPage';
            var fd = new FormData();
            fd.append('file', $('#imageSe')[0].files[0]);
            fd.append('title', $('#inputitle').val());
            fd.append('artist', $('#inputArtist').val());
            fd.append('twitter', $('#inputTwitter').val());
            $.ajax({
                url: url,
                type: 'POST',
                data: fd,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    album = data.data;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                console.log(textStatus, errorThrown);
            }
            });
});
tereško
  • 58,060
  • 25
  • 98
  • 150
DiogoDil
  • 9
  • 3
  • 2
    You probably don't want to set `contentType: false`, because the data you send *is* of a certain type/format. But whether that's the problem, I don't know. As far as code organization goes (and how to avoid sync calls), have a look [How to return the response from an AJAX call?](http://stackoverflow.com/q/14220321/218196). – Felix Kling Feb 25 '14 at 18:04
  • Why `contentType: false`??? – A. Wolff Feb 25 '14 at 18:05
  • because if I do not define false, my image does not come in the controller – DiogoDil Feb 25 '14 at 18:19

1 Answers1

0

https://api.jquery.com/jquery.ajax/#jQuery-ajax-settings has the note

Cross-domain requests... requests do not support synchronous operation.

Can this be a factor?

Also for "Why contentType: false", the same page has the note

As of jQuery 1.6 you can pass false to tell jQuery to not set any content type header.

There's a server that I have to work with that wants multipart without boundary strings. (don't have qp to comment)

aydow
  • 3,673
  • 2
  • 23
  • 40