Got probs with a nice exmaple. I used this Google map example and it is working with the local array created in the javascript: http://jsfiddle.net/jFMQ5/2/
现在我只需要改变它 从php获得阵列。
步骤是:
- create array in php
- convert array to json using json_encode
- grap it in javascript
在我的喷射器里,我得到了这个(也充满了发型错误, 但我猜这是另一个问题)
var arrAddress = ["Sir vej 3 7500 Holstebro","Ivar Lundgaardsvej 8 7500 Holstebro","Hu00f8jtoftvej 6 7500 Holstebro","Svalevu00e6nget 22 7500 Holstebro","Ringku00f8bingvej 21 7500 Holstebro","Elkju00e6rvej 90 7500 Holstebro","Hovedgaden 2 7500 Holstebro","Skolegade 32 7500 Holstebro","Fuglsangvej 2 7500 Holstebro","Slu00e5envej 150 7500 Holstebro","Burvej 2A Idom 7500 Holstebro"];
在jsfidd 例子中,它期待这样的阵列:
$arrAddress[0] = "Sir vej 3 7500 Holstebro";
$arrAddress[1] = "Ivar Lundgaardsvej 8 7500 Holstebro"
etc. etc.
如何使 Jsfidle 链接与这个 json 字符串有效, 而不是本地定义的数组?
UPDATE PHP is creating the array like this:
// in PHP //
While(...) {
$arrAddress[] = $row[ address ]. .$row[ zip ]. .$row[ city ];
}
// after while
$arrAddress = json_encode($arrAddress);
// end php //
// in javascript //
var addAddress = {$arrAddress}