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.
<?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 } } ?>
$("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.
public function actionSingleverse()
{
$verseid = $_POST['verseid'];
$langid = $_POST['langid'];
echo $verseid." ".$langid;
}
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.
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
Paste your url in the following format am sure it will work
url:'<?php echo Yii::app()->request->baseUrl;?>/index.php/controllername/singleverse',