我想將當前文章ID傳遞給ajax文件。 ajax文件的URL類似於www.web.com/plugins/system/ajax.php,所以使用JRequest :: getInt(id)總是分析0整數。在非ajax文件中,我可以用同樣的方法獲得ID。所以我想知道如何傳遞整數值,或者有其他方法可以在ajax文件中獲取文章ID?發送文章ID到ajax文件或直接在ajax文件中獲取文章ID?在joomla!插件
<?php
defined('_JEXEC') or die;
define('DS', DIRECTORY_SEPARATOR);
?>
<?php
class plgSystemRatingx extends JPlugin
{
public function onContentBeforeDisplay()
{
?>
<?php echo JRequest::getInt('id'); ?>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".like").click(function()
{
var id=$(this).attr("id");
var name=$(this).attr("name");
var dataString = 'id='+ id + '&name='+ name;
$("#votebox").slideDown("slow");
$("#flash").fadeIn("slow");
$.ajax
({
type: "POST",
url: "/joomla/plugins/system/ratingx/conf.php",
data: dataString,
cache: false,
success: function(html)
{
$("#flash").fadeOut("slow");
$("#content").html(html);
}
});
});
$(".close").click(function()
{
$("#votebox").slideUp("slow");
});
});
</script>
<?php echo JURI::current(); ?>
<div style="margin:50px">
<a href="#" class="like" id="1" name="up">Like</a> -- <a href="#" class="like" id="1" name="down">Dislike</a>
<div id="votebox">
<span id='close'><a href="#" class="close" title="Close This">X</a></span>
<div style="height:13px">
<div id="flash">Loading........</div>
</div>
<div id="content">
</div>
</div>
</div>
<?php
return true;
}
}
AJAX FILE:
<?php
// Set flag that this is a parent file
define('_JEXEC', 1);
// No direct access.
defined('_JEXEC') or die;
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', dirname(__FILE__).DS.'..'.DS.'..'.DS.'..');
require_once (JPATH_BASE .DS.'includes'.DS.'defines.php');
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php');
$db = &JFactory::getDbo();
if(JRequest::getInt('id'))
{
$id = JRequest::getInt('id');
$name = JRequest::getVar('name');
$queryx = "SELECT id from messages";
$db->setQuery($queryx);
$db->query($queryx);
$idx = $db->loadObjectList();
$query = "update messages set $name=$name+1 where id='$id'";
$db->setQuery($query);
$db->query($query) or die('blo5gai');
$query2 = "select up,down from messages where id='$id'";
$db->setQuery($query2);
$db->query($query2) or die('blo5gai');
$vote = $db->loadObject();
$up_value= $vote->up;
$down_value = $vote->down;
$total=$up_value+$down_value;
$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;
?>
<div style="margin-bottom:10px">
<b>Ratings for this blog</b> (<?php echo $total; ?> total)
</div>
<table width="700px">
<?php echo JURI::current(); ?>
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $up_value; ?></td>
<td width="600px"><div id="greebar" style="width:<?php echo $up_per; ?>%"></div></td>
</tr>
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $down_value; ?></td>
<td width="600px"><div id="redbar" style="width:<?php echo $down_per; ?>%"></div></td>
</tr>
</table>
<?php
}
你說的 「讓文章ID在AJAX文件」 是什麼意思?你想用阿賈克斯或其他東西來實際加載文章嗎? – Lodder
不,ajax文件用於將投票結果插入當前文章ID。 – Jonuux
我需要在ajax文件中有文章ID。 – Jonuux