Why content-type false AJAX - JQUERY

2

I'm sending files via AJAX with Jquery, using FormData() , and then a question has arisen, why it works:

$.ajax({
  url:"action/receipt.php",
  method:"POST",
  processData: false,
  contentType: false,
  data: form,
  success:function(data){

  }

});

And that's not it?

$.ajax({
  url:"action/receipt.php",
  method:"POST",
  processData: false,
  data: form,
  success:function(data){

  }

});

I mean, in the first way the variable $_FILES prints the expected values, in the second it is empty.

Why does not filling in the content-type result in $_FILES empty? Is it because the default is in a shipping format other than multipart/form-data , or am I traveling?

    
asked by anonymous 01.10.2015 / 16:27

2 answers

2

When you use contentType with the value false , you are forcing jQuery not to pass the default value to contentType of the request. The default, as previously mentioned, is application/x-www-form-urlencoded .

Probably, when done in the example below, jQuery will import this contentType information directly from form .

var f = new FormData($('#form').get(0));

$.ajax({ data: f, contentType: false, cache: false, processData: false})
    
01.10.2015 / 16:38
2
___ erkimt ___ Why content-type false AJAX - JQUERY ______ qstntxt ___

I'm sending files via AJAX with Jquery, using Content-Type , and then a question has arisen, why it works:

%pre%

And that's not it?

%pre%

I mean, in the first way the variable application/x-www-form-urlencoded prints the expected values, in the second it is empty.

Why does not filling in the content-type result in multipart/form-data empty? Is it because the default is in a shipping format other than %code% , or am I traveling?

    
______ azszpr90088 ___

When you use %code% with the value %code% , you are forcing jQuery not to pass the default value to %code% of the request. The default, as previously mentioned, is %code% .

Probably, when done in the example below, %code% will import this contentType information directly from %code% .

%pre%     
______ ___ azszpr90087

Yes, that's right. If you notice in the request effectively performed by the browser (using the development tools) will see that %code% %% standard is %code% , whose server-side processing is completely different from %code% .

    
___
01.10.2015 / 16:36