Best way to include unobtrusive information on a web page

前端 未结 7 942
栀梦
栀梦 2021-02-06 16:34

So I\'ve got some scripts I\'ve written which set up a Google map on my page. These scripts are in included in the of my page, and use jQuery to build

7条回答
  •  野性不改
    2021-02-06 17:24

    Gareth, you may want to take a look at JSON on http://www.json.org/

    Apart from the benefit of compactness it has got strong server side support and should you decide in the future to load the co-ordinates dynamically using HTTPRequest it would be very easy to do so without having to amend the existing script much.

    JSON — JavaScript Object Notation is effectively a native way of serializing JavaScript objects.

    Some examples here: http://www.json.org/example.html

    You can even store all of the address infromation in a JavaScript array of objects recorded in JSON and build the list on the screen dynamically. This will give you the ability to sort, filter and manipulate the addresses easilly in any way you need at "run time".

    The alternative way would be to embrace each address with a tag (a simple div will do) and introduce a new attribute for the tag containing the coordinates:

    17 Coldwell Drive
    Blue Mountain
    BA93 1PF
    United Kindom

    then

    var myCoordsCSV = $("addr1").coordinates;
    

    You can combine the second approach with JSON (store coordinates object) if you wish or add two attributes for each coordinate or keep a comma delimited list etc.

    The second approach also degrades nicely and is search bot friendly.

提交回复
热议问题