Ajax调用不起作用,但是正在刷新页面时正在调用函数

问题描述 投票:0回答:1

我正在编写一个AJAX调用,将作业标记为已打印,并以绿色突出显示表格行。刷新页面后,标记为已打印的作业将从表中消失。

问题是,当表格行以绿色突出显示时,作业没有被标记为已打印。当我刷新页面[[在任何时候时,该作业将被标记为已打印。我是AJAX的新手,所以我不知道哪里出了问题。

echo '<tr class="' . alternator('even', 'odd') . '" id="' . $job->id . '">'; echo '<td><a rel="ibox&width=350&height=100" href="#print' . $job->id . '">' . $job->reference . '</a>'; echo '<div id="print' . $job->id . '" style="display: none;">'; echo 'Are you sure you have printed the transcript(s) for job reference: <a href="' . site_url('job/editjob/' . $job->id) . '">' . $job->reference . '</a>?<br /><br />'; echo '&nbsp;<a class="boxbutton" href="#" id="markAsPrinted">Yes</a>'; echo '&nbsp;<a class="boxbutton" onclick="iBox.hide();">No</a></div></td>'; echo '</tr>';
JavaScript是:

<script type="text/javascript"> window.addEvent('domready', function(){ $('selectallmail').addEvent('click', function(e) { e.stop(); $$('.mailselector').each(function(el){ el.checked = true; }); }); $('markAsPrinted').addEvent('click', function(e) { e.stop(); let el = document.getElementById('<?php echo $job->id; ?>'); let u = '<?php echo $this->MJob->markAsPrinted($job->id); ?>'; let req = new Request.HTML({ method: 'get', url: u, data: { 'do' : '1' }, onComplete: function() { el.style.backgroundColor = 'lightgreen'; iBox.hide(); } }).send(); }); });

PHP函数:

function markAsPrinted($jobid) { if (empty($jobid)) { return false; } $this->logchange($jobid, 'Mark as printed.'); $this->memcache->delete('job' . $jobid, 0); $this->memcache->delete('listitem' . $jobid, 0); $this->db->update('job', array('printed' => 1), 'id = ' . $jobid); return ($this->db->affected_rows() == 1); }

编辑:

<div id="invoicing_jobs_table"> <form action="<?php echo site_url('invoice/markasmailed'); ?>" method="post"> <a href="#" id="selectallmail">Select All</a><br /> <table width="100%"> <tr class="odd"> <th>&nbsp;</th> <th>Ref #</th> <th>Client</th> <th>Job Type</th> <th>Pages</th> <th>Inv Date</th> <th style="text-align:right;">Invoice Total</th> <th style="text-align:center;">Paid</th> </tr> <?php $printingids = $printingjobs->getIds(); foreach ($mailingjobs as $job){ if ($job->jobtypeid == 307) continue; // NYC DoE echo '<tr class="' . alternator('even', 'odd') . '">'; echo '<td>' . (in_array($job->id, $printingids) ? '&nbsp' : '<input type="checkbox" name="mailjobs[]" value="' . $job->id . '" class="mailselector" />') . '</td>'; echo '<td>' . $job->reference . '</td>'; echo '<td>' . $job->client . '</td>'; echo '<td>' . $job->jobtype->name . '</td>'; echo '<td>' . $job->pagecount . '</td>'; $inv = $job->invoices[0]; echo '<td style="white-space:nowrap;">' . date('M d, Y', $inv['idate']) . '</td>'; echo '<td style="text-align:right;">$' . sprintf('%.2f', $inv['total']) . '</td>'; echo '<td style="text-align:center;">' . ($inv['paid'] ? 'Yes' : 'No') . '</td>'; echo '</tr>'; } ?> </table><br /> <input type="submit" value="Mark as mailed" class="boxbutton" /> </form>
php ajax mootools
1个回答
0
投票
$('markAsPrinted')必须为$('#markAsPrinted'),因为它被声明为ID

<a class="boxbutton" href="#" id="markAsPrinted">Yes</a>

$('selectallmail')$('#selectallmail')相同。它是某些html组件的ID。
© www.soinside.com 2019 - 2024. All rights reserved.