I would recommend the solution of geographikas, and also tried to use various js classes to improve maintainability and readability. Do not do everything in the same object, create your own pop-up object that inherits or uses OpenLayers.Popup.Anchored or something else, and make an Ajax call from there. This way you will not clutter up your other code with this. Also simplifies reuse and replacement if necessary.
I would go for something like this (untested!):
mynamespace.mypopup = function(o) {
var size = new OpenLayer.Size(100, 70);
var icon = new OpenLayers.Icon();
var popup = new OpenLayers.Popup.Anchored(o.id, o.lonlat, size, getContent(), icon, false, null);
var getContent = function() {
}
return popup;
}
in a file called "mypopup.js"
and name it with:
var popup = new mynamespace.mypopup({id: 'whatever', lonlat: myLonLat});
source
share