Welcome Guest, Not a member yet? Register   Sign In
xajax function arguments not passing, missing arguments warning
#1

[eluser]CodeIgniter Fan[/eluser]
Hi

Please help my xajax function not getting arguments. I got warning missing arguments 1 for myajaxfunction(). I am sending my table id by onclick button event.

Need urgent help.

Thanks in advance.
#2

[eluser]Michael Wales[/eluser]
Please paste your code - it's impossible to assist without that.
#3

[eluser]CodeIgniter Fan[/eluser]
Code:
class Articles extends Controller {

    function Articles()
    {
        parent::Controller();

        $this->load->helper('url');
    }

function ratearticle($value,$article_id)
    {
        $this->load->library('xajax');

        $this->db->select('total_ratings,rating');
        $currentratings = $this->db->getwhere("articles_ratings",array('article_id'=>$article_id));
        if($currentratings->num_rows()>0)
        {
            /*currently assuming no ratings has been added for article table is empty so not doing anything here and we will work default values in else statement*/
        }
        else
        {
            $totalvotes = 0;
            $rating = 0;
            $new_count = ($totalvotes + 1);
            $tut_rating2 = ($rating * $totalvotes);
            $new_rating = (($value + $tut_rating2) / ($new_count));
            $new_rating2 = number_format($new_rating, 2, '.', '');
            $insertdata['article_id'] = $article_id;
            $insertdata['total_ratings'] = $new_count;
            $insertdata['rating'] = $new_rating2;
            $this->db->insert("articles_ratings",$insertdata);
            $objResponse = new xajaxResponse();
            $objResponse->addAssign("ratings","innerHTML", "check");
            return $objResponse->getXML();
        }
    }

   function viewarticle()
    {
        $articleid = $this->uri->segment(2);
        $data['article'] = $this->db->getwhere('articles',array('id'=>$articleid));
        if($data['article']->num_rows()>0)
        {
            $row1 = $data['article']->row();
            $subcatid = $row1->category;

            $this->db->select('parent_id,category_name');
            $getparentid = $this->db->getwhere('categories',array('id'=>$subcatid));

            $row2 = $getparentid->row();
            $data['subcategoryname'] = $row2->category_name;
            $parentid = $row2->parent_id;

            $this->db->select('category_name');
            $parentcategoryname = $this->db->getwhere('categories',array('id'=>$parentid));
            $row3 = $parentcategoryname->row();
            $maincategoryname = $row3->category_name;

            $data['maincat'] = $this->_getmaincategories();
            $data['subcat'] = $this->_getsubcategories($parentid);

            $totalcomments = $this->db->query("select id from articles_comments where article_id=".$articleid." and status=1");
            $data['total_comments']= $totalcomments->num_rows();

            $data['breadcrumbs'] = "<li><a href='".base_url()."'>Home&nbsp;</a></li>";
            $data['breadcrumbs'] .= "<li><a href='?subcategory/".$maincategoryname."/".$parentid."'>".$maincategoryname."&nbsp;</a></li>";
            $data['breadcrumbs'] .= "<li><a href='?viewarticles/".$data['subcategoryname']."/".$subcatid."'>".$data['subcategoryname']."&nbsp;</a></li>";
            $data['breadcrumbs'] .= "<li>".$row1->title."</li>";

            //xajax loading starts here
            $this->load->library('xajax');
            $this->xajax->registerFunction(array('ratearticle',&$this,'ratearticle'));
            $this->xajax->setRequestURI(site_url().'articles/ratearticle');
            $this->xajax->processRequests();
            $data['xajax_js'] = $this->xajax->getJavascript(null,'js/xajax.js');
            //xajax loading ends here

            $this->load->view('view_article',$data);
        }
        else
        {
            $data = $this->_dorequired1();

            $data['breadcrumbs'] = "<li><a href='".base_url()."'>Home&nbsp;</a></li>";
            $data['breadcrumbs'] .= "<li>Page not found</li>";

            $this->load->view('view_notfound',$data);
        }
    }

I am working on windows IIS server

Reply Thanks.
#4

[eluser]CodeIgniter Fan[/eluser]
My ratearticle() xajax function is for rating article and I am sending two value through button's onclick event (1)user selected value from dropdown box and (2)article id
#5

[eluser]CodeIgniter Fan[/eluser]
I am going to sleep now its 2:00 AM in India hope there will be post with solution when I will check tomorrow.

I also tried this by removing currently all code and added this

Code:
$this->load->library('xajax');
        $objResponse = new xajaxResponse();
        $objResponse->addalert(print_r($_POST));

and I got this in alert box

Code:
Array
{
[xajax]=>ratearticle
[xajaxr]=>1192478272265
[xajaxargs]=>Array
{
   [0]=>5.0
   [1]=>1
}
}

but with warning of missing argument 1 and 2 for Article:ratearticle().So values are going in post variable but ratearticle() does not receive it.

Please help to solve this.

Thanks.
#6

[eluser]Sally D[/eluser]
I think you should comment your code more to make it more clearer

Your code is not commented well enough if you want help you really should heavily comment your code. That just me though
#7

[eluser]CodeIgniter Fan[/eluser]
Please help guys. I cant solve it yet. I am getting missing arguments warning for my xajax function. My controller "articles" contains xajax function ratearticle($value,$article_id). than please tell me how I have to set the request uri in setRequestUri() function of xajax ?
#8

[eluser]ELRafael[/eluser]
how is the view (fine thanks!) that calls xajax_ratearticule()???

seems all ok in your controller (sorry, i didn't ready all)
#9

[eluser]CodeIgniter Fan[/eluser]
unsolved yet
#10

[eluser]!Z[/eluser]
Try this

Move these lines to the constructor
Code:
$this->load->library('xajax');
$this->xajax->registerFunction(array('ratearticle',&$this,'ratearticle'));
$this->xajax->processRequests();

Delete this line of everywhere
Code:
$this->xajax->setRequestURI(site_url().'articles/ratearticle');

I see that you are using an old version of xajax, I suggest that you move to 0.5

Bye.




Theme © iAndrew 2016 - Forum software by © MyBB