trying to call javascript - 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: trying to call javascript (/showthread.php?tid=73547) Pages:
1
2
|
trying to call javascript - richb201 - 05-07-2019 I realize that js is really a client thing and not a server thing. Anyway, I am trying to call Code: $(register_extension( PHP Code: $this->load->js("/js/javascript_funcs_extensionloaded.js"); A PHP Error was encountered Severity: Error Message: Call to undefined function javascript_funcs_extensionloaded() Filename: controllers/Configure.php Line Number: 43 Can anyone tell me how to look at this? RE: trying to call javascript - php_rocs - 05-07-2019 @richb201, Are you trying to have your web app send a browser message? RE: trying to call javascript - richb201 - 05-07-2019 (05-07-2019, 07:03 PM)php_rocs Wrote: @richb201, Not really. I am trying to have the browser page send a message to the extension of the browser. There is some messaging facility in chrome. So I want the web page (which was built by the server), to make a call to the js which will send the message. Or is that what you meant? I did ask a similar thing recently, but I am just trying to get the js to run on a page created by grocery crud or code igniter. My overall plan is to call the aws javascript api from the extension. But I need to communicate some instructions from CI created browser page before I do that. People say that the Extension "runs in the context of the browser". I am not sure what that means, honestly, other than I can use some chrome runtime messaging feature (see the code above). But the only way I can communicate using the Chrome messaging app is to call a js function from my php created web page. I guess the js needs to be embedded in the html but I don't know how to do that. Is the problem that I need to call register_extension() from the CI code? How does CI know I am calling a js function? RE: trying to call javascript - richb201 - 05-08-2019 I changed the function call in my php program to $this->load->js("/js/javascript_funcs_extensionloaded.js"); register_extension(); I am getting error: call to undefined function register_extension() Now I tried: echo "<script> register_extension(); </script>"; but need to put a debugger on the extension to see if it actually ran. RE: trying to call javascript - InsiteFX - 05-08-2019 Try adding the function to a var Code: /** RE: trying to call javascript - richb201 - 05-09-2019 Thanks. How do I call it from my controller? I tried calling it from echo "<script> webApp(); </script>"; I am getting these errors in my xdebug window: Uncaught ReferenceError: webApp is not defined Uncaught ReferenceError: $ is not defined Uncaught SyntaxError: Unexpected token var RE: trying to call javascript - InsiteFX - 05-09-2019 It already loads all the functions see the init function, then at the bottom you can see that it loads itself. The only way that I know how it to check the page post value then send an ajax call. Code: $(document).ready(function(){ Something like that you need to set it up for your stuff. The url would point to your controller method. RE: trying to call javascript - richb201 - 05-09-2019 Thanks insite. What I really need is a document written for beginners trying to call javascript from a php generated html page. I understand the xmlhttp stuff. My extension uses that to communicate back to my server. Works great, after much pain. I just need my web app to initiate a message to my Extension. I control bought sides. My plan is to write a .png to aws S3 directly from the extension. I could send the .png to my server and have my server upload it to S3 in php, but that would be wasteful of bandwidth, which costs $. So if you know how I can simply get my javascript function to be called from my controller, I will work out the messaging details. RE: trying to call javascript - InsiteFX - 05-10-2019 You can try this one out to see if it will work for you. Code: <html> You can also try to echo it from your controller. RE: trying to call javascript - richb201 - 05-10-2019 I changed the call in my controller to: $this->load->js("/js/javascript_funcs_extensionloaded.js"); echo '<script type="text/javascript" > register_extension(); </script>'; I just can't tell if it is running. I put a breakpoint in my js register_extension module, but phpStorm is not stopping there. I think my xdebug is set correctly. It seems that I don't know how to declare a javascript function in my php program. I found this is the documentation re:Javascript Class "This library is DEPRECATED and should not be used. It has always been with an ‘experimental’ status and is now no longer supported. Currently only kept for backwards compatibility." OK, so it was taken out . But what do the rest of us do now? I am getting these errors in my console: index:1
Uncaught ReferenceError: register_extension is not defined javascript_funcs.js:1
Uncaught ReferenceError: $ is not defined Uncaught SyntaxError: Unexpected token var index
Here is the javascript $(register_extension( var editorExtensionId = "lamacgnkfoiknjpleghfknfigbmhdaei"; // Make a simple request: chrome.runtime.sendMessage(editorExtensionId, "snapshot_mode", function(response) { if (!response.success) handleError(url); }) ) There seems to be something BIG I am missing here? It would seem that I would need to tell the PHP program that register_extension() is a valid javascript function? |