1

I can post only image and get it with $_FILES['foto']['name']. I need post image and text same time.

        var fotoFile = new FormData();
        $('#foto').on('change', function (evt) {
            var files = evt.target.files;
            if (files.length > 0) {
                fotoFile.append("foto", files[0]);
            }
        });

It is post code

`                $.ajax({
                    url: 'postpages/personelsave.php', 
                    dataType: 'text',
                    type: 'post',
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: {foto : fotoFile, tc_no : document.getElementById('tcNo').value},                         
                    success: function(php_script_response){
                        alert(php_script_response);
                    }
                });`

and personelsave.php

$_FILES['foto']['type']
$_POST["tc_no"]

Error : undefined index foto.

What is wrong with it?

Circas Creed
  • 95
  • 1
  • 8

2 Answers2

0

You can't use multiple dataTypes, if you use JSONP this will return a jsonp block which you could use to call a callback to handle the return data like this:

Basic example of using .ajax() with JSONP?

So through JSONP you can handle multiple dataTypes.

Bhavin
  • 2,070
  • 6
  • 35
  • 54
0

Just use below to submit all types of input data including file

var formData = new FormData($("#formID")[0]);
$.ajax({
    type: "POST",
    url: 'postpages/personelsave.php', 
    data: formData,
    processData: false,
    contentType: false,
});
Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47