我想为此网站 http://www.shoesofprey.com/3d/designer?p=20600P4
首先,人们选择他们想要的样式,然后他们选择他们想要的颜色。我需要构建一个这样的脚本(不添加到购物车)。
我认为无论他们点击什么都存储为会话,然后从该会话中php脚本选择一个图像。
这是我所做的,但它仍然不起作用:
index.php中的
<script language='javascript'>
function getXMLHTTP() { //function to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getpic(strURL) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('getimg').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function createRequestObject() {
var ro;
ro = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'rpc.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|') != -1) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
</script>
<table>
<tr>
<td>
<a href="javascript:sndReq('top')">[TOP]</a>
<a href="javascript:sndReq('bottom')">[BOTTOM]</a>
</td>
<td>
<div id="getimg" style="width:600px;height:450px;border:1px solid #ccc;border-radius:10px;">
<img src="img/polos.jpg">
</div>
</td>
<td>
<div id="foo">
<label><input name="color" type="radio" value="black"> black </label><br/><br/>
<label><input name="color" type="radio" value="blue"> blue </label><br/><br/>
<label><input name="color" type="radio" value="brown"> brown </label><br/><br/>
<label><input name="color" type="radio" value="red"> red </label><br/><br/>
</div>
</td>
</tr>
</table>
rpc.php中的
switch($_REQUEST['action']) {
case 'top':
/* do something */
session_start();
// store session data
$_SESSION['top']="t";
echo "foo|"?>
<label><input name="color" type="radio" value="1" onChange="getpic('http://localhost/distrokl/img.php?tcl='+this.value)"> blue </label><br/><br/>
<label><input name="color" type="radio" value="2" onChange="getpic('http://localhost/distrokl/img.php?tcl='+this.value)"> brown </label><br/><br/>
<label><input name="color" type="radio" value="3" onChange="getpic('http://localhost/distrokl/img.php?tcl='+this.value)"> red </label><br/><br/>
<?;
break;
case 'bottom':
/* do something */
session_start();
// store session data
$_SESSION['bottom']="b";
echo "foo|"?>
<label><input name="color" type="radio" value="1" onChange="getpic('http://localhost/distrokl/img.php?bcl='+this.value)"> blue </label><br/><br/>
<label><input name="color" type="radio" value="2" onChange="getpic('http://localhost/distrokl/img.php?bcl='+this.value)"> brown </label><br/><br/>
<label><input name="color" type="radio" value="3" onChange="getpic('http://localhost/distrokl/img.php?bcl='+this.value)"> red </label><br/><br/>
<?;
break;
}
**and in img.php**
session_start();
$tcl = $_REQUEST['tcl'];
$_SESSION['tcl']=$tcl;
$bcl = $_REQUEST['bcl'];
$_SESSION['bcl']=$bcl;
$top = $_SESSION['top'];
$bottom = $_SESSION['bottom'];
$topcl = $_SESSION['tcl'];
$botcl = $_SESSION['bcl'];
echo "<img src='img/".$top.$topcl.$bottom.$botcl".jpg'><br/>";
关于我需要做什么的任何想法?