Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8071063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:35:02+00:00 2026-06-05T13:35:02+00:00

i am trying to call a function which is defined in another js file

  • 0

i am trying to call a function which is defined in another js file by afterAjaxUpdate paramter of the file name but i got error in console that function is not defined

<?php 
$dataProvider=new CActiveDataProvider('profiles',array('pagination'=>array('pageSize'=>3))); ?>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_profilesview',
'template'=>'{sorter}<br />{pager}{items}{pager}',
    'enableSorting' => true,
    'sortableAttributes'=>array(
     'name'=>'By firstName',
     'location'=>'By city',
     'age'=>'By age',
     'likes'=>'By likes'
     ),
     'afterAjaxUpdate'=>'readcookie()',
));
 ?>

my js function is

$(document).ready(function(){
   function readcookie()
   {
       alert("hi");
   }
});

i can see in my source that function defined in the file is included after all the js files that are included by yii default
when i register my script in my layout it dosent find $ because jquery not included when i include jquery it gets included twice which leads to trigger my event
i also tried to by setting

renderPartial(‘Mybelowview’,null,false,true)

which leads again my js file to include multiple times and my event gots trigger multiple time.

This is very confusing please help to get out of it
Thanks all for being so generous

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:35:04+00:00Added an answer on June 5, 2026 at 1:35 pm

    The problem is that functions inside $(document).ready(); are out of scope outside of it, and that’s why you get undefined. So you can either just have:

    // $(document).ready(function(){
       function readcookie()
       {
           alert("hi");
       }
    // });
    // omit document.ready to make function available in the global scope
    

    or define the function on the window object to make it global:

    $(document).ready(function(){
       window.readcookie=function ()
       {
           alert("hi");
       };
    });
    

    Lastly define the attribute 'afterAjaxUpdate' as :

    'afterAjaxUpdate'=>'readcookie'
    // if it is readcookie() it becomes a function call instead
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi guys i am trying to call a function which is defined in main.mxml
trying to make a page which will recursively call a function until a limit
I'm currently trying to register a JS function call from a .NET page which
I have the following C++ function definition, which I am trying to call through
I was trying to call a function that was allocated in the heap. After
I'm trying to call a function from a form within the same .php file,
I'm trying to call a function that contains jQuery code. I want this function
I'm trying to call a function, and VS gives me an error (red underline),
I'm trying to call a function in the onclick event of the button that
I'm trying to call an external Delphi function from C# which takes a Delphi

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.