duanchuang3182 2013-12-11 12:53
浏览 56

如何在yii中使用Ajax,JQuery

I am using Ajax and jQuery in yii.

I have a view its url is like that.

http://localhost/UnderstandQuran/index.php?r=Verse/topicverse&topic_id=1

Now there are some radio buttons group. When i click on it, it will be called by jquery.

My View Code.

<?php $i= 0;
foreach($data->verse_lang as $vtlanguage) {
$i = $i+1 ;
if($i === 1) { ?>
<input type="radio" name="<?php echo "tran".$data->id ?>" class="translanguage" langid="<?php echo $vtlanguage['id']; ?>" verseid="<?php echo $data->id ?>" checked="checked"><?php echo $vtlanguage['language_name']; ?></input>
<?php } else { ?>
<input type="radio" name="<?php echo "tran".$data->id ?>" class="translanguage" langid="<?php echo $vtlanguage['id']; ?>" verseid="<?php echo $data->id ?>"><?php echo $vtlanguage['language_name']; ?></input>
<?php } } ?>

My JQuery Code

$("input[type='radio'][class='translanguage']").click(function ()
{
    var siteUrl = document.URL;
    var verseid = $(this).attr("verseid");
    var langid = $(this).attr("langid");
    var vname = $(this).attr("name");

    $.ajax(
    {
        type: "POST",
        url: siteUrl + "/singleverse",
        data:
        {
            verseid: verseid,
            langid: langid
        },
        success: function (result)
        {
            alert(result);
        }
    });
});

Through Ajax, i am sending it to the controller/Controller Method.

My Controller Method

public function actionSingleverse()
{
    $verseid = $_POST['verseid'];
    $langid = $_POST['langid'];
    echo $verseid." ".$langid;
}

My Question

Now through all of my code. It should be giving the alert box with two different integer value, but it is displaying all the html code of the page. So how i can solve this issue. I have checked in console.log, but gives 505 error.

My all this code is working fine when the above URL is like that.

http://localhost/UnderstandQuran/index.php?r=Verse

Please help me, what and where is the problem.

Thanks.

  • 写回答

2条回答 默认 最新

  • drfm55597 2013-12-11 13:52
    关注

    May be there will be some problem in this place

    var siteUrl = document.URL;
    

    The Site Url can also be got in javascript like this

    var siteUrl = <?php echo Yii::app()->getBaseUrl() ?>;
    

    May be this could help you

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题