user3731557 user3731557 - 29 days ago 16
PHP Question

ajax multipart/form-data post charset utf-8

i have a form with upload file and input text that requires an utf-8 encoding, when i try to send the form trough ajax i can't change the contentType: false so how can i protect my text as well!?

$.ajax({
url : 'url';?>',
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData:false,
success: function(data)
{

alert 'ok';


}

Answer

You can use this code on form submit:

$("#formId").submit(function(){

    var formData = new FormData($(this)[0]);

    $.ajax({
        url: 'your_url',
        type: 'POST',
        data: formData,
        async: false,
        success: function (data) {
            alert(data)
        },
        cache: false,
        contentType: false,
        processData: false
    });

    return false;
});
Comments