CodeIgniter Forums
calling javascript function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: calling javascript function (/showthread.php?tid=75022)



calling javascript function - richb201 - 12-09-2019

My php code is running along fine. At some point I make this call:

$this->load->view("javascript_funcs_extensionloaded","snapshot_mode2");

The javascript_funcs_extensionloaded.js is in my /js directory. 

I have put some breakpoints in the javascript_funcs_extensionloaded file, but they never get triggered. So either phpStorm is not allowing me to debug a js file, or the js file is not really loading or being called correctly. Any idea on how to resolve this? 


RE: calling javascript function - Wouter60 - 12-10-2019

(12-09-2019, 08:09 PM)richb201 Wrote: My php code is running along fine. At some point I make this call:
$this->load->view("javascript_funcs_extensionloaded","snapshot_mode2");

$this->load->view($file, $data)  assumes that the file is a php file in the application/views folder.
If you have a javascript_funcs_extensionloaded.php file, which - on it's turn - loads a javascript file in your /js folder, make sure you make the correct reference to the js folder.
Best way IMO is:
PHP Code:
<script src="<?= base_url();?>js/script_filename.js" /> 
Put this code at the top of your view.


RE: calling javascript function - richb201 - 12-10-2019

Let's see if I understand? I should change the line in my calling php file to:

$this->load->view('javascript_funcs_extensionloaded.php');

And at the top of javascript_funcs_extensionloaded.php I should have

<script src="<?= base_url();?>js/javascript_funcs_extensionloaded.js" />

???


RE: calling javascript function - Wouter60 - 12-10-2019

That's right.
There's a chance that it only works if you also use the <script> closing tag:
PHP Code:
<script src="..."></script



RE: calling javascript function - InsiteFX - 12-10-2019

You can always see what is going on by using your web browsers development tools F12 console.


RE: calling javascript function - richb201 - 12-10-2019

Insite, I use the chrome debugger extensively to debug the Extension.  The problem is "where do I put the breakpoint"? What I am doing is sending some data from the php program to the Extension. But it never seems to arrive at the Extension. I'd like to see what fails in the .js function call but phpStorm will not allow me to debug a .js file. So I opened up the Chrome debugger on the js/javascript_funcs_extensionloaded.js file and put a breakpoint in the main function init. But it is not getting triggered.


I might have a hint. I took a look in the log and I see:

ERROR - 2019-12-11 03:32:23 --> Severity: 8192 --> idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated /app/system/libraries/Form_validation.php 1234

Does anyone know what this is and why I am getting it?


RE: calling javascript function - richb201 - 12-11-2019

This is the .js file being referenced. I never see any data being transfered. 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script language="javascript">

  var nc = $.noConflict()
// Code that uses other library's $ can follow here.


    nc(document).ready( function() {
        var editorExtensionId = "lamacgnkfoiknjpleghfknfigbmhdaei";
        // unload when done
        nc(window).on('beforeunload',(function(){
            chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode_unload")
        }))


//    alert (data);
        //      chrome.runtime.sendMessage(editorExtensionId, data,
        chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode1",
            function (response) {
                if (!response.success)
                    handleError(url);

            }
        )

    })


    </script>