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

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:
HTML
<button id="1a" type="button">Click here</button>

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

$(document).ready(function() {

$("#123456").click(function(event){ 
$.post(
"test.php",
testobject 
);

});
});

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.

Regards,
Ramakrishna
Posted
Updated 5-Oct-15 19:00pm
v2

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:
https://en.wikipedia.org/wiki/Ajax_(programming)[^],
see also http://api.jquery.com/category/ajax[^].

—SA
 
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