Jump to content

Connecting Js To Php - Solved With Thanks


niche

Recommended Posts

I need to create a dynamic link. My link is: <a href="javascript:void(0);" onclick="miniatures()">miniatures</a> My js function (so far): function miniatures() {var selection = "miniatures";//send js var to php var//call header} How do I send the value in a js var to a php var? How do I call a header in javascript (load a url)?

Link to comment
Share on other sites

Thanks for your help JSG.I figured out how to send and use data as part a url (first time working with the $_GET array), but I haven't found the way to turn a js var into a php var with ajax. Can you direct me to the appropriate part of the ajax tutorial? I don't see the part that turns a js var into a php var?

Link to comment
Share on other sites

well, you make a request to the script. in the url you pass parameters, which are name/value pairs. i.e

www.mydomain.com/myscript.php?param1=somevalue&param2=someothervalue//orxmlHttpObj.open('GET','myscript.php?param1=somevalue&param2=someothervalue',false)

so, if you are making an AJAX request (POST/GET), or even just an HTTP request via the browsers address bar (only GET), then they are available to the script that way.

<?php$param1 = $_GET['param1'];$param2 = $_GET['param2']; echo $param1;  //displays 'somevalue'echo $param2;  //displays 'someothervalue' ?> 

if you use AJAX w/POST, then obviously you have to switch to POST in your script instead.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...