CodeIgniter Forums

Full Version: calling javascript function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 [font=DejaVu Sans Mono]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? [/font]
(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.
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" />

???
That's right.
There's a chance that it only works if you also use the <script> closing tag:
PHP Code:
<script src="..."></script
You can always see what is going on by using your web browsers development tools F12 console.
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?
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>