CodeIgniter Forums
two views with javascript. One works, one doesn't. Why? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: two views with javascript. One works, one doesn't. Why? (/showthread.php?tid=73687)



two views with javascript. One works, one doesn't. Why? - richb201 - 05-22-2019

I am using javascript to create 2 messages that I am sending from my CI program to my Chrome Extension. This is the first one that seems to run fine. I am calling it from a method in one of my controllers. The message snapshot_mode is correctly sent to the Chrome Extension.
Code:
<script language="javascript">

   $(document).ready( function() {
       var editorExtensionId = "lamacgnkfoiknjpleghfknfigbmhdaei";

       // Make a simple request:
       chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode",
           function (response) {
               if (!response.success)
                   handleError(url);

           }
       )
   })

</script>


Later, when the user logs off the application I am calling this from a different function in the same controller:
Code:
<script language="javascript">



       var editorExtensionId = "lamacgnkfoiknjpleghfknfigbmhdaei";

       // Make a simple request:
       chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode_unload",
           function (response) {
               if (!response.success)
                   handleError(url);

           }
       )


</script>
Almost exactly the same, right? The unload doesn't work. I haven't been able to debug the javascript code in phpStorm, but I know that the message is not arriving at the Extension. It is true in the code that shortly after calling the unload function above, I am clearing the session and then redirecting. Without debugging both the php and javascript at the same time, how can I solve this problem?


RE: two views with javascript. One works, one doesn't. Why? - InsiteFX - 05-22-2019

Have you tried using your browsers development tools F12 ?

Bring up the developer tools in the console tab and watch what the javascript is doing etc;


RE: two views with javascript. One works, one doesn't. Why? - richb201 - 05-22-2019

Ill try that. It is funny that the one with the .ready works but the "naked" one doesn't.