Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将文章id发送到ajax文件还是直接在ajax文件中获取文章id?在乔姆拉!插件_Javascript_Php_Ajax_Plugins_Joomla - Fatal编程技术网

Javascript 将文章id发送到ajax文件还是直接在ajax文件中获取文章id?在乔姆拉!插件

Javascript 将文章id发送到ajax文件还是直接在ajax文件中获取文章id?在乔姆拉!插件,javascript,php,ajax,plugins,joomla,Javascript,Php,Ajax,Plugins,Joomla,我想将当前文章id传递给ajax文件。ajax文件的Url类似于www.web.com/plugins/system/ajax.php,所以使用JRequest::getIntid总是解析0整数。在非ajax文件中,我可以用同样的方法获取ID。所以我想知道如何传递整数值,或者有其他方法在ajax文件中获取文章id <?php defined( '_JEXEC' ) or die; define( 'DS', DIRECTORY_SEPARATOR ); ?> <?php cl

我想将当前文章id传递给ajax文件。ajax文件的Url类似于www.web.com/plugins/system/ajax.php,所以使用JRequest::getIntid总是解析0整数。在非ajax文件中,我可以用同样的方法获取ID。所以我想知道如何传递整数值,或者有其他方法在ajax文件中获取文章id

<?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文件:

<?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

}

您必须添加一个属性作为vid,并通过vid属性传递id的值

例如:

<a href="#" class="like" id="1" name="up" vid="<?php echo JRequest::getInt('id'); ?>">Like</a> 
在脚本文件中,必须像这样调用属性

<script type="text/javascript">
    $(document).ready(function()
    {
        $(".like").click(function()
        {
            var vid=$(this).attr("vid");
            alert(vid);
        }
    });
</script>

在ajax文件中获取文章id是什么意思?您想使用ajax或其他方式加载文章吗?不,ajax文件用于将投票结果插入当前文章id。我需要在ajax文件中有文章id。请尝试以下url:/joomla/plugins/system/ratingx/conf.php?aid=,…在您的插件文件中使用$id=JRequest::getInt'aid';我编辑了第一篇文章,我想你可能想看看代码的样子。我试过了,认为你提交的代码在这里不起作用,但是谢谢。我还是不明白。如何在mysql查询中使用此变量$query=更新消息集$name=$name+1,其中id='$id'$db->setQuery$query$db->query$query或die'blo5gai'$query2=从id='$id'的消息中选择向上、向下$db->setQuery$query2$db->query$query2或die'blo5gai';您正在询问有关查询的信息。此处$query->set'name=。$name+1$名称是一个字符串。所以不能使用$name+1
<?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' );

$id = JRequest::getInt('id');
$db = &JFactory::getDbo();

if($id)
{       
    $name   = JRequest::getVar('name');

    $query->select('id');
    $query->from('messages');   
    $db->setQuery($query);
    $db->query($query);
    $idx = $db->loadResult();


    $query->update('messages');
    $query->set('name = '.$name+1);
    $query->where('id='.$id);
    $db->setQuery($query);
    $db->query();

    $query->select('up,down');
    $query->from('messages');
    $query->where('id='.$id);
    $db->setQuery($query);
    $db->query($query);
    $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

}