Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure what your specific problem is, but there are certainly a number of things that you could do to improve the overall design.</p> <p>Firstly, are you sure that this is even something that you want to do in Javascript? It seems like you are modifying a text file on your server to tell your pages which ads to serve. That's alright, but if you have the option, it would be better to do this server side. Just include the appropriate urls to the images before you send the HTML back to the users browser using PHP or a similar language if you have access to do so. This removes complexity from your code, improves page load speed, and properly displays your ads even without proper Javascript support.</p> <p>If you are going to do this with AJAX, then I would highly recommend using JSON formatted data and some type of library to handle the request for you. Parsing text files presents a number of problems, and formatting data as JSON gives you a cheap way to convert it to a Javascript object. jQuery is one popular choice for doing this: <a href="http://api.jquery.com/jQuery.getJSON/" rel="nofollow">http://api.jquery.com/jQuery.getJSON/</a></p> <p>You could format your file more like:</p> <pre><code>{ "img": "http://myhost/img/mm.jpg" "link": "http://myhost/" "width": "192" "height": "108" } </code></pre> <p>Then you would need to do something like this to update the image field on your page:</p> <pre><code>$.getJSON("test.js", function(json) { $.each(json, function(key, value) { //parse the keys and values appropriately in here }); }); </code></pre> <p>You also probably don't want to use document.write. This overwrites the entire content of the page. You probably want to select your image element in some way and then change its attributes. You can use jQuery selectors for this. See the section on manipulation for ways to modify the img element once you've selected it.</p> <p><a href="http://api.jquery.com/category/selectors/" rel="nofollow">http://api.jquery.com/category/selectors/</a></p> <p><a href="http://api.jquery.com/category/manipulation/" rel="nofollow">http://api.jquery.com/category/manipulation/</a></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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