Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!