简体   繁体   English

如何从codeigniter控制器方法调用在codeigniter视图中定义的js函数?

[英]how to call a js function defined in a codeigniter view from codeigniter controller method?

This is my contoller function ni want to call developer() function defined in a view called chat_developer. 这是我的contoller函数,我想调用在称为chat_developer的视图中定义的developer()函数。

function developer_via_superadmin() {
    echo '<script>'
    . 'developer();'
    . '</script>';
  }

Here is the devleloper function defined in the view 这是在视图中定义的devleloper函数

script>
     function developer() {
       alert("Developer function called from controller");    
    }
   </script>

But when i call it from controller. 但是当我从控制器调用它时。 Console gives an error 控制台出现错误

Uncaught ReferenceError: developer is not defined

You should place the JS function some where above the place where you call it. 您应该将JS函数放置在调用它的位置上方。 ie as the error says, the function must be defined before it could be called. 即,如错误所述,必须先定义函数,然后才能调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM