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

257
Visualizações
How to call Php function with js params

I need to call php function inside javascript with js params. something like.

function test(data) {
    $.each(data,function(key, item) {
        let resVal = '{{encryptId('+item.id+') }}';
    })
}

encryptId is a function defined in php helper file.

Please suggest can it work

Thanks!!

about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

That's not possible but a way around it could be using ajax requests. You can hit the function of php through javascript and also send parameters.

about 4 years ago · Santiago Trujillo Relatório

0

This is not possible, PHP and javascript are executed at different time,

Your PHP is executed on the server, before any data is sent to the client, the server himself has no idea about what javascript is

Your javascript is executed on the client, after he received all the code preformated by PHP, the client doesn't know what PHP is nor how to interpret it

The only way to do it is to have the same function in javascript

about 4 years ago · Santiago Trujillo Relatório

0

Javascript ran on the Client Side (ie the browser) and PHP was a server side tool (ie the Server side). CLEARLY the two just cant interact.

you can try with AJAX

#JS FILE
function encryptId(item) {
    .ajax {
        file : phpFile
        item : item
    }
}

function test(data) {
    $.each(data,function(key, item) {
        encryptId(item.id)        
    })
}

#PHP FILE
Here You can catch that variable and call this function
about 4 years ago · Santiago Trujillo 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