【发布时间】:2012-04-01 14:20:13
【问题描述】:
在 Firebug(使用 FirePHP 插件)中,我注意到与 PHP 文件没有通信,因此没有任何反应...
这是 Javascript:
// three parameters are required by Dojo!
function buildMenu(type, data, evt)
{
var menuDOM = document.getElementById("colorselect");
var nextColor, nextItem;
// delete previous items in the color menu
menuDOM.options.length = null;
// split the data into an array of colors
var colors = data.split(', ');
// go through the returned array of colors
for(var i = 0; i < colors.length; index++)
{
nextColor = colors[i];
nextItem = new Option(nextColor);
/* add the new item to the menu
("null" for IE5, "-1" for all other browsers) */
try
{
menuDOM.add(nextItem, -1);
}
catch(e)
{
menuDOM.add(nextItem, null);
}
}
} // end of function buildMenu
// the function that calls bind to request data
function getColors(size)
{
dojo.io.bind( {url: "shirtColors.php" + "?size=" + size,
load: buildMenu,
method: "GET",
mimetype: "text/plain"
} );
}<br /><br />
这里是 PHP:
<?php
$shirtSize = $_GET["size"];
// array for available colors (for each shirt size)
$colors = array("large" => "black, yellow, green",
"medium" => "blue, purple, white, off-white, cream, bleached-white",
"small" => "orange, red, aqua, turqoise, aquamarine, light-blue");
echo $colors[$shirtSize];
?><br /><br />
...这里是html:
(Dojo在这里链接到网上,Dojo io库是导入的)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shirt Colors</title>
<!-- link to dojo online -->
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js"></script>
<!-- javascript file -->
<script type = "text/javascript" src = "shirtColors.js"></script>
<!-- import the dojo io library -->
<script type = "text/javascript">
dojo.require("dojo.io.*");
</script>
</head>
<body>
<select onchange = "getColors(this.value);">
<option value = "large">
large shirt
</option>
<option value = "medium">
medium shirt
</option>
<option value = "small">
small shirt
</option>
</select>
<select id = "colorselect"></select>
</body>
</html>
【问题讨论】:
标签: php javascript ajax dojo