我需要一些帮助来发送我的数据。
首先,我为之工作的脚本被用作Nagios的Mass Acknoledgments工具,受到了NagiosXI可购买组件的高度启发。我最后一次开发了它,数据处理/发送完全是用PHP编写的。实际上,我喜欢我的脚本,要做到这一点,我需要使用AJAX。
我遇到的问题是:下面是我的表单屏幕,生成它的html代码,Chrome调试工具的屏幕,显示数据是如何发送的,以及用于数据检索的PHP代码。
<tr>
<td class="OK">168VWL1</td>
<td><a href="javascript:checkAll('host1');">Check all for this hosts</a></td>
<td class="empty"></td>
<td class="empty"></td>
<td class="empty"></td>
<td class="empty"></td>
</tr>
<tr>
<td class="empty"></td>
<td class="critical"><input class="host1 servicecheck" type="checkbox" name="services[]" value="168VWL1::Explorer">Explorer</td>
<td class="output">Explorer.exe: not running</td>
<td class="centerd"><input type="checkbox" class="sticky" name="sticky[]" value="168VWL1::Explorer"></td>
<td class="centerd"><input type="checkbox" class="notify" name="notify[]" value="168VWL1::Explorer"></td>
<td class="centerd"><input type="checkbox" class="persist" name="persist[]" value="168VWL1::Explorer"></td>
</tr>
if(isset($_POST['hosts'])){
$allHosts = json_decode($_POST['hosts']);}
if(isset($_POST['services'])){
$allServices = json_decode($_POST['services']);}
if(isset($_POST['sticky'])){
$allStickys = json_decode($_POST['sticky']);}
if(isset($_POST['notify'])){
$allNotifys = json_decode($_POST['notify']);}
if(isset($_POST['persistent'])){
$allPersistents = json_decode($_POST['persistent']);}
正如您所看到的,通过这样做,在PHP中处理我的数据非常简单,只是一个调用,并且已经生成了我的数组。
现在,由于我使用AJAX,我不知道如何以相同的方式发送这个文件。有什么建议吗?
发布于 2016-03-08 10:20:26
序列化和发送表单数据-
var formData = $('.campaign-form').serialize();
$.ajax({
type: 'post',
url: POST_URL_HERE,
data: formData,
success: function(data)
{
console.log(data);
}
});
发布于 2016-03-08 10:15:21
$('#form1').serialize()
使用ajax发送表单数据
https://stackoverflow.com/questions/35864513
复制相似问题