伙计们,我有一个搜索输入,并发送它的值到 AJAX ,并成功地显示在一个div的结果,我可以发送的值(id)到另一个 AJAX 再一次?我已经尝试过了,但是没有在firebug中发送任何东西,这是从html发送id值到 AJAX 然后发送到cari.php在div中显示结果的程序流(responsecontainer),并从 AJAX jquery结果,我想发送id值到显示细节的第二个ajax。
this is my jquery
$('.cariinvbranch').click(function(e) {
var branch = $("#branch").val();
var status = $("#status").val();
$.ajax({
type: "POST",
url: "pages/cari.php",
data: 'branch='+branch+'&status='+status,
success: function(response){
$("#responsecontainer").html(response);
//alert(data);
}
});
});
$(document).ready(function(){
$('.detil').click(function(e) {
var id = $(this).attr('id');
var dataString = 'id='+ id ;
alert(dataString);
$.ajax({
type: "POST",
url: "pages/detil.php",
data: dataString,
success: function(response){
$("#responsecontainer").html(response);
}
});
});
$('.cariinvbranch').click(function(e) {
var branch = $("#branch").val();
var status = $("#status").val();
$.ajax({
type: "POST",
url: "pages/cari.php",
data: 'branch='+branch+'&status='+status,
success: function(response){
$("#responsecontainer").html(response);
//alert(data);
}
});
});
my html
<select name='branch' id='branch' class='searchtoolbar' >
<option></option>
<?php
$query = $database->GetBranch();
while($row = mysql_fetch_array($query))
{
echo "<option value=$row[branch]>$row[branch]</option>";
}
?>
</select>
<select name='status' id='status' class='searchtoolbar'>
<option></option>
<?php
$query = $database->GetStatus();
while($row = mysql_fetch_array($query))
{
echo "<option value=$row[asset_status]>$row[asset_status]</option>";
}
?>
</select>
<a href ='#' class='cariinvbranch' id='branch'>Cari</a>
<div ='responsecontainer'>
<result here from search>
</div>
-------------------------------------------------------------
cari.php
<?php
// if($_POST['branch'] !== '' AND $_POST['status'] !== ''){
include_once('../include/classes/session.php');
if(strlen($_POST['branch']) < 1){
$_POST['branch'];
$status = $_POST['status'];
$result1 = $database->getPcAsset();
$num_rows1 = mysql_num_rows($result1);
for ($i = 0; $i < $num_rows1; $i++) {
$idx = mysql_result($result1,$i,'idx');}
$result=$database->CariInvStatusAll($status);
$numrows = mysql_num_rows($result);
echo "<table id = 'asset'>
<tr class = 'header'>
<td>
<input type='checkbox' name='cek'>
</td>
<td>
Name
</td>
<td>
Model
</td>
<td>
OS
</td>
<td>
Asset Status
</td>
<td>
Branch
</td>
<td>
SN
</td>
</tr>
</table>";
for($i=0;$i<$numrows;$i++){
$idx = mysql_result($result,$i,'idx');
$name = mysql_result($result,$i,'name');
$model = mysql_result($result,$i,'model');
$operation_system = mysql_result($result,$i,'operation_system');
$asset_status = mysql_result($result,$i,'asset_status');
$branch = mysql_result($result,$i,'branch');
$serial_number = mysql_result($result,$i,'serial_number');
echo "
<table>
<tr>
<td>
<input type='checkbox' name='cek'>
</td>
<td>
<a href='#' class='detil' id='$idx'>$name<a>
$idx
</td>
<td>
$model
</td>
<td>
$operation_system
</td>
<td>
$asset_status
</td>
<td>
$branch
</td>
<td>
$serial_number
</td>
</tr>
</table>";
}
----------------------------------------------------
detil.php
<?php
include_once ("../include/classes/session.php");
$id = $_POST['id'];
$result = $database->getDetilPcAsset($id);
$num_rows = mysql_num_rows($result);
for ($i = 0; $i < $num_rows; $i++) {
$idx = mysql_result($result,$i,'idx');
$name = mysql_result($result,$i,'name');
$model = mysql_result($result,$i,'model');
$manufacturer = mysql_result($result,$i,'manufacturer');
$purchasing_date = mysql_result($result,$i,'purchasing_date');
$operation_system = mysql_result($result,$i,'operation_system');
$ipaddress = mysql_result($result,$i,'ipaddress');
$asset_status = mysql_result($result,$i,'asset_status');
$branch = mysql_result($result,$i,'branch');
$location = mysql_result($result,$i,'location');
$serial_number = mysql_result($result,$i,'serial_number');
$warranty_expired = mysql_result($result,$i,'warranty_expired');
$delivered_date = mysql_result($result,$i,'delivered_date');
$pic = mysql_result($result,$i,'pic');
$installation_date = mysql_result($result,$i,'installation_date');
$requested_by = mysql_result($result,$i,'requested_by');
$vendor_name = mysql_result($result,$i,'vendor_name');
echo "<table id='tableassetdetil'>
<tr>
<td>
Name
</td>
<td>
:
</td>
<td>
$name
</td>
</tr>
<tr>
<td>
Manufacturer
</td>
<td>
:
</td>
<td>
$manufacturer
</td>
</tr>
<tr>
<td>
purchasing_date
</td>
<td>
:
</td>
<td>
$purchasing_date
</td>
</tr>
<tr>
<td>
operation_system
</td>
<td>
:
</td>
<td>
$operation_system
</td>
</tr>
<tr>
<td>
ipaddress
</td>
<td>
:
</td>
<td>
$ipaddress
</td>
</tr>
<tr>
<td>
asset_status
</td>
<td>
:
</td>
<td>
$asset_status
</td>
</tr>
<tr>
<td>
branch
</td>
<td>
:
</td>
<td>
$branch
</td>
</tr>
<tr>
<td>
location
</td>
<td>
:
</td>
<td>
$location
</td>
</tr>
<tr>
<td>
serial_number
</td>
<td>
:
</td>
<td>
$serial_number
</td>
</tr>
<tr>
<td>
warranty_expired
</td>
<td>
:
</td>
<td>
$warranty_expired
</td>
</tr>
<tr>
<td>
delivered_date
</td>
<td>
:
</td>
<td>
$delivered_date
</td>
</tr>
<tr>
<td>
pic
</td>
<td>
:
</td>
<td>
$pic
</td>
</tr>
<tr>
<td>
installation_date
</td>
<td>
:
</td>
<td>
$installation_date
</td>
</tr>
<tr>
<td>
requested_by
</td>
<td>
:
</td>
</td>
<td>
$requested_by
</td>
</tr>
<tr>
<td>
vendor_name
</td>
<td>
:
</td>
<td>
$vendor_name
</td>
</tr>
</table> ";
}
?>
2条答案
按热度按时间mzsu5hc01#
您可以使用键值对
{key1: 'value1', key2: 'value2'}
pxiryf3j2#
我没有看到任何
.detil
元素在你的代码。无论如何,你应该使用.on()
方法,这样你的脚本将通过当前元素集查看。因为在你加载 AJAX 内容后,.click()
不会看到新元素。这是文档中的link for .on()。
并考虑使用对象。