/    Sign up×
Community /Pin to ProfileBookmark

Calling a PHP page through Javascript

Dear all,

I must call a PHP page with a Javascript command.

I developed a function that does almost exactly what I needed:

View code: Example 1

But in the last part where it makes me “view” (document.getElementById(‘showResult’)) only the result, I need to do it in a way that instead calls me another PHP page, where it will execute the instructions passed in this page.

//Example 1

“`
function getCheckedValues()
{
return Array.from(document.querySelectorAll(‘input[type=”checkbox”]’))
.filter((checkbox) => checkbox.checked)
.map((checkbox) => checkbox.value);
}

const resultEl = document.getElementById(‘result’);

document.getElementById(‘showResult’).addEventListener(‘click’, () =>{
resultEl.innerHTML = getCheckedValues();

});
“`

//Link that should I call through the function:

<p>
https://localhost.test:8085/live/backofficeNew/Tests/controller/sendToPhysicianSampleID.php?idList=BIY53423 </p>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Programming_PadawanDec 31.2021 — JavaScript is client side programming and PHP is server side programming. The client side code is loaded into and executed by your web browser. Server side code remains on the server. The two are not in the same geological location at run time.

In order to execute a PHP function from JavaScript you will need to make a request to the server. This can be done through the JavaScript "fetch" function. With fetch you can send a request to the server for a specific PHP script to be executed, and receives the response. 'fetch' is JavaScript Promise based so I would recommend you become familiar with JavaScript Promises.

PHP usually runs through modules installed in an Apache web server. I am using JavaScript for my dynamic user interface and PHP is doing all the hard work on an Apache web server loaded on my Debian Linux system. There **might** be a Node.js module for PHP.

Hope this helps

W.
×

Success!

Help @WIPE spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...