我处于两难境地,并不确定最佳方法。我使用的代码使用ajax查询php并成功返回数据。但是,我有一个从单击事件触发的表单,我需要做的是从该表单中捕获值并附加到我已经拥有的数据,以便我可以发送到php进行数据库处理。
简要情景:
如果数据==' New Intake'这会触发表单,当按下操作按钮时,捕获表单值以与现有数据连接并发送到php进行处理。
我已经看了一段时间了,看不出怎么做,所以帖子。如果有人帮我找到解决办法,我将不胜感激。我使用jtable来显示和处理数据,我只发布了代码的相关部分,因为它很长。非常感谢
的jQuery / AJAX
sendbtn: {
title: 'Action',
width: '1%',
sorting: false,
edit: false,
display: function(data) {
var $image = $('<span><img src="css/themes/lightcolor/icon-action.png" style="display: block; margin: 0 auto; cursor:pointer;"/></span>');
$image.click(function() {
var $selectedRows = $('#setActionsScheduleShow').jtable('selectedRows');
$selectedRows.each(function() {
var record = $(this).data('record');
var id = record.id;
var service = record.service;
var dept = record.department;
var activity = record.activity;
var company = record.company;
var user = record.user;
var item = record.item;
var address = record.address;
//alert(id + ' ' + service + ' ' + activity + ' ' + dept + ' ' + company);
var data = {
id: id,
service: service,
company: company,
dept: dept,
activity: activity,
user: user,
item: item,
address: address
}
$.ajax({
type: "POST",
url: "boxActionTemp.php",
data: data,
success: function(data) {
//alert(data);
if (data == 'error') {
notif({
msg: 'There was an error actioning your request.<br />' + 'Please inform the system administrator.' + 'Thank you.',
type: "default",
position: "center",
width: 490,
height: 75,
multiline: true,
timeout: 6000,
autohide: true,
opacity: 0.9,
fade: 10,
});
} else if (data == 'New Intake') {
//alert ('new Intake');
$('#rackInput').show();
var $dialog = $('#rackIntakeForm');
$dialog.dialog({
autoOpen: true,
modal: true,
title: 'Please input your rack details',
width: 280,
height: 280,
draggable: true,
resizable: false,
close: function(event, ui) {
$("#rackIntakeForm").validate().resetForm();
//$( this ).dialog( "close" );
$("#rackIntakeForm").get(0).reset();
$("#rack, #column, #row, #bay").val(' ');
}
// buttons: {
//Close: function() {
//$( this ).dialog( "close" );
//$("#frmreport").get(0).reset();
// }
// }
});
} else {
notif({
msg: 'You have successfully actioned your request for ' + activity + '<br /><br /><b><font color="black">' + data + '</b></font>' + '<br /><br />This update was successfully added to the database.<br /><br />Thank you.',
type: "defaultSuccess",
position: "center",
width: 490,
height: 75,
multiline: true,
timeout: 6000,
autohide: true,
opacity: 0.9,
fade: 10,
});
$('#setActionsScheduleShow').jtable('load');
}
}
});
});
});
return $image;
}
}
boxActionTemp.php
<?php
session_start();
$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
//If this Fails at least place it in a JSON so you can see IT
$db = mysql_select_db("sample");
// test vars from jquery form
$id = mysql_real_escape_string($_POST['id']);
$company = mysql_real_escape_string($_POST['company']);
$user = mysql_real_escape_string($_POST['user']);
$activity = mysql_real_escape_string($_POST['activity']);
$service = mysql_real_escape_string($_POST['service']);
$item = mysql_real_escape_string($_POST['item']);
$address = mysql_real_escape_string($_POST['address']);
$newdate = $date[2] . '-' . $date[1] . '-' . $date[0];
$Displaydate = $date[0] . '-' . $date[1] . '-' . $date[2];
$qty = mysql_real_escape_string($_POST['rcyqty']); // never used */
$authorised = mysql_real_escape_string($_SESSION['kt_name_usr']);
$dept = mysql_real_escape_string($_POST['dept']);
if ($id == "")
{
echo 'error';
}
else if ($activity == 'New Intake')
{
echo 'New Intake';
}
else
{
$output = 'Company: ' . ' ' . $company;
$output .= '<br />';
$output .= 'Address: ' . ' ' . $address;
$output .= '<br />';
$output .= 'User: ' . ' ' . $user;
$output .= '<br />';
$output .= 'Activity: ' . ' ' . $activity;
$output .= '<br />';
$output .= 'Service: ' . ' ' . $service;
$output .= '<br />';
$output .= 'Item: ' . ' ' . $item;
echo ($output);
/* $sql = "INSERT INTO `act` (service, activity, department, company, address, user, date, quantity, type, new)";
$sql .= "VALUES ('$service', '$activity', '$dept', '$company', '$address', '$requested', NOW(), '$qty', '$type', 1)";
$result = mysql_query($sql) or die ('{"opp":"error","box":"' . mysql_error() . '"}'); */
}
?>
HTML
<form id="rackIntakeForm" method="post">
<table id="rackTable" border="0">
<tr>
<td>Rack:</td>
<td></td>
<td><input id="rack" name="rack"></td>
</tr>
<tr>
<td>Column:</td>
<td></td>
<td><input id="column" name="column"></td>
</tr>
<tr>
<td>Row:</td>
<td></td>
<td><input id="row" name="row"></td>
</tr>
<tr>
<td>Bay:</td>
<td></td>
<td><input id="bay" name="bay"></td>
</tr>
<tr>
<td>Size:</td>
<td></td>
<td>
<select id="boxSelect" name="size">
<option value="" selected> Choose box size </option>
<option value="S"> Standard </option>
<option value="P"> Printout </option>
<option value="O"> Other </option>
<option value="T"> Transfer </option>
</select>
</td>
<br />
</tr>
<tr>
<td></td>
<td></td>
<td><br /><input class="addprofilesubmit" type="submit" name="submit" value="Action"></td>
</tr>
</table>
</form>