Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
jquery ajax Send string data and file data PHP

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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,
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda