嗨,我在发布选择节点的值时遇到问题,但什么也得不到。我正在使用 dojo/request。当我使用简单的 ajax 文件进行测试时,服务器上的 getuser1.php 正在工作。
在请求行,数据值可能不正确
请指教...谢谢
以下是两个脚本:- main.php 文件-
require(["dojo/parser", "dojo/ready","dijit/form/Select",
"dojo/request","dojo/on","dojo/domReady!"],
function(parser, ready, Select, request, on){
ready(function(){
console.debug('Rendering...');
var selectX = new Select({
name:'select_test',
options:[
{label:"<span class='NotinUse'><b>   . . .</b></span>", value:'0', selected:true},
{label:"<span class='inUse'><b>  Peter Griffin</b></span>", value:'1'},
{label:"<span class='inUse'><b>  Lois Griffin</b></span>", value:'2'},
{label:"<span class='inUse'><b>  Joseph Swanson</b></span>", value:'3'},
{label:"<span class='inUse'><b>  Glenn Quagmire</b></span>", value:'4'},
],
style:{width:'150px'}
},"select");
on(formNode2, 'Change', function(evt){
evt.stopPropagation();
evt.preventDefault();
request.post('getuser1.php',{
data:{select_test:this.value},
timeout:2000
}).then(function(response){
dom.byId('line2').innerHTML=response;
});
});
});
});
getuser1.php 文件:-
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', '');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ajax_demo", $con);
$sql="SELECT * FROM user WHERE id = $q";
$result = mysql_query($sql);
// use stored function to return one result instead later. Write here after stored procedure has been stored.
echo "<table border='1'>
<tr>
<th width=100>Firstname</th>
<th width=100>Lastname</th>
<th width=100>Age</th>
<th width=100>Height</th>
<th width=100>Hometown</th>
<th width=100>Job</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Height'] . "</td>";
echo "<td>" . $row['Hometown'] . "</td>";
echo "<td>" . $row['Job'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>