Php 如何通过jQuery显示数组值?
我想使用jQuery或ajax在script.php文件上逐个发送多个select的选定值。发送script.php文件上的值后。我想在index.php页面特定输入框中显示script.php文件查询结果。例如:如果有人选择项目,则项目说明和费率显示在说明和费率输入框中。这是我的代码和图片 index.php文件代码:Php 如何通过jQuery显示数组值?,php,jquery,ajax,invoice,Php,Jquery,Ajax,Invoice,我想使用jQuery或ajax在script.php文件上逐个发送多个select的选定值。发送script.php文件上的值后。我想在index.php页面特定输入框中显示script.php文件查询结果。例如:如果有人选择项目,则项目说明和费率显示在说明和费率输入框中。这是我的代码和图片 index.php文件代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> &
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Item Description</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".item").change(function() {
var item = [];
item:$(".item").each(function() {
var num = parseFloat(this.value) || 1;
item.push(num);
});
$.ajax({
type: "POST",
url: "script.php",
data: item,
success: function()
{
// I failed to show script.php value
}
});
return false;
});
});
</script>
<style type="text/css">
table
{
border: 1px solid black;
border-bottom: none;
width: 600px;
}
td
{
border-left: 1px solid black;
border-bottom: 1px solid black;
padding:5px 5px 5px 5px;
}
#first
{
border-left: none;
border-bottom: 1px solid black;
}
</style>
</head>
<body>
<form method='post' name='form1' action='welcome.php'>
<table cellpadding="0" cellspacing="0">
<tr>
<td id="first">Item</td>
<td>Description</td>
<td>Rate</td>
</tr>
<?php
$num=4;
for ($i=0; $i<$num; $i++)
{
echo "
<tr>
<td id='first'>
<Select class='item' name='item[]'/>
<option>Select one</option>
<option>Deluxe Plan</option>
<option>Premium Plan</option>
<option>Standard Plan</option>
<option>Economy Plan</option>
</select>
</td>
<td><textarea class='description' type='text' name='description[]'></textarea></td>
<td><input class='rate' type='text' name='rate[]'/></td>
</tr>";
}
?>
</table>
</form>
</body>
</html>
script.php文件代码
<?php
include "dbconnect.php";
$item=$_REQUEST['item'];
$query="select * from item where item_name='$item'";
$result=mysql_query or die (mysql_error());
while ($row = mysql_fetch_array($result))
{
$description=$row['description'];
$rate=$row['rate'];
}
?>
请任何人帮我解决这个问题 试试这个
data: { 'item' : item.serializeArray() }
在将阵列发送到服务器之前对其进行序列化
success: function(result) {
}
您使用页面中的数据参数并将其发送到服务器。。。
您可以使用这些数据查询某个结果,然后以轻量级的JSON格式返回结果
来自服务器的返回结果可以在AJAX请求的成功回调函数中处理,该函数可用于操作DOM
检查此链接:iteam:$.iteam.eachfunction{没有任何意义-它可能会破坏您的脚本-在每个循环之前删除iteam:,但是如何在index.php页面上显示我的script.php文件查询结果。请解释一下