Jquery, Javascript, and XML-Need Help! |
[eluser]zimco[/eluser]
I am trying to get the data values from an XML file and use them with the GnuBookreader, but am totally confused with using CI, jquery, javascript, and the XML file together. I have gotten as far as reading the values from the XML file with Jquery and writing them back to the screen, but now want to put those values in variables that the GnuBookreader script can use. I am hoping somebody with alot more experience with javascript and jquery can point me in the right direction. The XML file looks like this: Code: <?xml version="1.0" encoding="iso-8859-1"?> My CI template file loads the following in the header: Code: <head> CI VIEW file looks like this: Code: <div id="bookreader"> MY javascript file, GnuBookTest.js it just reads the XML file and spits parse back to the screen. Code: $(document).ready(function() { GNUBOOK JAVASCRIPT EXAMPLE that uses static values set right in the script, rather than what i would like to do: which is use the values from the XML file. Code: // This file shows the minimum you need to provide to GnuBook to display a book
[eluser]Sean Gates[/eluser]
@zimco If I understand your dilemma correctly, I think you're on the right track. But, I think there may be a better way: 1) I think you could do the request with CURL (in a model) 2) In the model put the necessary values in an array 3) Then build the GnuBook Javascript as a view, making it fully dynamic. 4) Last, you could just call the new JS view with something like: Code: <script src="/controller/gdjs" type="text/javascript"></script> Let me know if my thinking is off base, but I believe this would work better for you in the long run. More PHP, less JS. -- Sean
[eluser]zimco[/eluser]
Sean thanks for taking a look at my problem. Love the thought of more PHP, less javascipt. However, i don't think curl will help me out in this situation as the XML file resides on my server. Also, i have already tried the simplexml_load_file($file) idea in the controller and putting the values in a php array, but then always run into the problem of you can't pass variables from PHP to an external [removed] one is server side, one is client side. Javascript cannot interact with PHP before it's parsed by the server, blah blah blah. So now i'm trying to get the XML values directly in the external javascript file using jquery and have gotten as far as above, but am now lost as to how to get the xml values returned to the GnuBookreader script part.
[eluser]Sean Gates[/eluser]
[quote author="zimco" date="1263239439"]However, i don't think curl will help me out in this situation as the XML file resides on my server. Also, i have already tried the simplexml_load_file($file)[/quote] Yeah, this is where I was headed. [quote author="zimco" date="1263239439"]... you can't pass variables from PHP to an external [removed] one is server side, one is client side. Javascript cannot interact with PHP before it's parsed by the server, blah blah blah.[/quote] I guess I don't understand what you mean by this. You should be able to create a view that then creates a dynamic JS file for you. Then, through AJAX, you can just call this dynamic JS view anytime you need new variables, and PHP will be creating the JS the entire time.
[eluser]zimco[/eluser]
Quote:I guess I don’t understand what you mean by this. You should be able to create a view that then creates a dynamic JS file for you. Then, through AJAX, you can just call this dynamic JS view anytime you need new variables, and PHP will be creating the JS the entire time. I think it would take a computer science teacher to explain it, but all i can say is try doing what you propose: set your php variables in a controller and send along to view, create an external javascrpt file with references to your variables in it and drop that in a js folder, then call the view that contains the call to the javascrpt. You'll get an undefined variable error. In any case, i still have not figured out to get my XML data to the GnuBookreader script and am now reading ajax, json, jquery, and javascript tutorials and books. Thanks for trying to help.
[eluser]Sen Hu[/eluser]
Script using biterscripting - just one more option - it will create a table of leafnum, width and height. Code: # Script ExtractXML.txt Save the script in file "C:/Scripts/ExtractXML.txt", start biterscripting ( http://www.biterscripting.com ), run the following command. Code: script "C:/Scripts/ExtractXML.txt" xmldoc("http://www.somesite.com/some/path/somedoc.xml") The script will read the XML from internet and show you the TSV data. |
Welcome Guest, Not a member yet? Register Sign In |