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.