Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda