![](/img/trans.png)
[英]Drupal 7 ajax not working properly (success function called but the drupal page is being printed instead of the page callbacks results)
[英]Ajax call is not working, but function is being called on page refresh
任何人?
我正在編寫一個 AJAX 調用(使用 MooTools)來將作業標記為已打印並以綠色突出顯示表格行。 刷新頁面時,標記為已打印的作業將從表格中消失。
問題是,雖然表格行以綠色突出顯示,但作業沒有被標記為已打印。 當我在任何時候刷新頁面時,該作業就會被標記為已打印。 我對 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 ' <a class="boxbutton" href="#" id="markAsPrinted">Yes</a>';
echo ' <a class="boxbutton" onclick="iBox.hide();">No</a></div></td>';
echo '</tr>';
JavaScript 是:
<script type="text/javascript">
window.addEvent('domready', function(){
$('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:
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);
}
$('markAsPrinted')
需要$('#markAsPrinted')
因為它被聲明為 ID
<a class="boxbutton" href="#" id="markAsPrinted">Yes</a>
$('selectallmail')
與$('#selectallmail')
。 它是一些 html 組件的 id。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.