I'm trying to send a file to the php file through ajax, the problem is when I try to send the data I need to sent it as String (mandatory) to locate the controller and the action (function) in this way:
jQuery.ajax({
type: "POST",
url: "/app/controllers/router.php",
data: {
controller: 'resource_management/language_control', action: "createLanguageControl", user: User, language: Language, course: Course, begin_date: BeginDate, end_date: EndDate, installments: Installments, monthly_amount: MonthlyAmount, max_reimbursement: MaxReimbursement, currency: Currency, TempDir : tempDir, DocName : docName
},
cache: false,
success: function (r) {
...
});
So it passes by the router and read the controller and the action by string. How do I sent the file?
You can try something like this :
var file = "someFile.csv";
var data = new FormData();
var controllerData = JSON.stringify({
controller: "resource_management/language_control",
action: "createLanguageControl",
.....
});
data.append("file", file);
data.append("string", controllerData);
$.ajax({
url: '/app/controllers/router.php',
method: "POST",
data: data,
contentType: false,
processData: false,
});