Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few things to note...</p> <p>1.) If you go to the script's URL directly and check the media type/mime is is text/javascript? If not it some browsers may not execute any scripting in the file regardless of if all the scripting is written perfectly.</p> <p>2.) You can execute PHP code in JavaScript files with JavaScript extensions (e.g. example.js) by using the following .htaccess command...</p> <pre><code>AddHandler application/x-httpd-php .js .example2 .example3 AddType text/javascript .js </code></pre> <p>If you're trying to use a dynamic path (which is commendable) you can't put an object inside of quotes otherwise it'll be treated as a string instead of an object.</p> <pre><code>var path = 'http://localhost/site1/'; alert(path+'scripts/example.js'); </code></pre> <p>3.) Try to contain your scripts only to the scripts directory and only include script files inside the head element. This will force you to write better JavaScript. For those who complain about loading scripts after content use the defer attribute...</p> <pre><code>&lt;head&gt; &lt;script defer="defer" src="scripts/index.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script defer="defer" src="scripts/onload.js" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; </code></pre> <p>4.) Merge your scripts between two files, index.js and onload.js. The onload.js file should only contain an anonymous onload function and global variables (variables not inside of any kind of function)...</p> <pre><code>var global_var = 'use these sparingly'; var path = 'http://localhost/'&lt;?php echo 'something/'; /* dynamically make this work on localhost and example.com, use print_r($_SERVER); to get started */ ?&gt;'; window.onload = function() { function_1('parameter_1','parameter_2'); function_2('parameter_1','parameter_2'); } </code></pre> <p>5.) You can keep multiple .js files separately and merge them in to a single index.js file using PHP so that it will still be easy to work with. If you want a very useful tool I highly recommend using Advanced Find and Replace to find and or replace scripts very quickly in your work.</p> <p>6.) Use single quotes for JavaScript and double quotes for (X)HTML. Consistency in how you code is a very valuable practice that pays off well once you get in to the swing of it.</p> <p>7.) I highly recommend using PHP to dynamically use the $_SERVER variable to help you set the var path in JavaScript so that the exact same code will work both on localhost and on your live domains (e.g. example.com) without having to modify anything. A competent programmer will always test their code in practice before committing it to a live environment, otherwise it's very easy to irk visitors because of even simple problems which can snowball because of issues like files being cached and the browser won't let go of the bad copy.</p> <p>8.) Since you're using PHP stick to using single quotes unless you really need to use double quotes. If you're not aware of the difference...</p> <pre><code>$e = 'aaa'; echo '123$e';//outouts 123$3 echo "123$e";//outouts 123aaa </code></pre> <p>9.) You can use alert(typeof object); to determine the context of the object (e.g. object (arrays are called objects in JavaScript), string, integer (number), etc.</p> <p>10.) NEVER use simple terms for function names or variable names (e.g. var open = ''; or function open() {}). There are reserved names in JavaScript and using them will cause you to pull out all of your hair in certain browsers that don't tell you that is why the script won't run (and won't trigger any errors or warnings) such as Internet Explorer. Try to use good naming schemes such as function ajax_upload(), var option_this, var option_that, etc. Editors such as SuperEdi have a functions panel, so you can group your AJAX functions and order them by name (e.g. ajax_1_init, ajax_2_build, ajax_3_request, ajax_4_handler, ajax_5_etc).</p> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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