Click here to Skip to main content
15,742,973 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)

I have a requirement to pass the javascript object to a PHP file & load that PHP file in browswer when a button is clicked.

index.html has the following code:
<button id="1a" type="button">Click here</button>

custom.js has the following code:
var testobject={'element1':1, 'element2':2}

$(document).ready(function() {



But I don't know to write a php file to receive this data.
Also I am not able to understand how to load this php file

Could anyone please help.

Thanks in advance.

Updated 5-Oct-15 19:00pm

1 solution

You really need to understand what client side and server side really do. If you mean client-side JavaScript embedded in a browser (from your question, it's hardly anything else), you never ever pass any variables from JavaScript to PHP, which is on the server side. All you do on the client side to the server side is sending HTTP request and receiving HTTP response. You can send an HTTP request through either a Web form or Ajax:[^],
see also[^].

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900