Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming the dom element exists in the second page, it should look something like this.</p> <p>JS:</p> <pre><code>function packDomData(){ return { "MySpecificYetBriefProperty0":1, "DomID":"divID", "MySpecificYetBriefProperty1":['a','b'], "MySpecificYetBriefProperty2":[1,2] }; } function useDomData(domData){ document.getElementByID(domData.DomID).innerHTML=domData.MySpecificYetBriefProperty1[0]; } </code></pre> <p>PHP:</p> <pre><code>//Make sure the contents of this file is the json from packDomData. use json_encode in php or JSON.stringify in js echo file_get_contents("text_file.txt"); var myData = JSON.parse(XMLHttpRequestObject.responseText); useDomData(myData); </code></pre> <p>I used to code like you. Here are some tips that have helped turn my coding horror into a fun job: </p> <ul> <li>Use objects with descriptive properties instead of arrays whenever you aren't actually looping through the array - I promise it will save you and others headache! "DomID" is much more flexible than 1, and if you change the order in the array, javascript gods help you that array is everywhere - including however many random text files on your server!</li> <li>Also use descriptive names for functions</li> <li>Always return a value from a function instead of using globals whenever possible, even where the result is then used as a nasty global. Trust me.</li> <li>Never put javascript function names in an ajax call. Use JSON instead and keep the functions and other script in the javascript file where it belongs.</li> <li>Mysql will save your life!!</li> </ul> <p>Disclaimer - I didn't run this code but it should basically work when you get everything hooked up right. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload