我有一个Struts2的Web上的GoogleMaps。我想加载它们保存在SQL DDBB标记列表。要做到这一点,我试图用jQuery和Ajax。在这里,您是code:
I have an Struts2 Web with GoogleMaps. I want to load a list of markers which are saved in a SQL DDBB. To do this, I tried with jQuery and Ajax. Here you are the code:
loadMarkers.java
loadMarkers.java
public class loadMarkers extends ActionSupport implements ServletRequestAware,ServletResponseAware{
//Variables de sesion/cookie
FunctionClass ses;
protected HttpServletResponse servletResponse;
protected HttpServletRequest servletRequest;
private String userID="";
//Variables del marker
private List<marker> markersList = new ArrayList<marker>();
public String execute() throws Exception{
FunctionClass friends = new FunctionClass();
//Leemos de la cookie
for(Cookie c : servletRequest.getCookies()) {
if (c.getName().equals("userID"))
userID = (c.getValue());
}
System.out.println("en el loadMarkers");
connectionBBDD con = new connectionBBDD();
markersList = con.loadMarkers(userID);
return SUCCESS;
}
我想使用markerList数组在Javascript中,创造了标记。
I want to use the markerList array in Javascript, to create the markers.
这是在struts.xml文件:
This is the struts.xml file:
<package name="jsonActions" namespace="/test" extends="json-default">
<action name="LoadMarkers" class="web.localizadroid.maps.loadMarkers">
<interceptor-ref name="basicStack"/>
<result type="json">
<param name="root">markersList</param>
</result>
</action>
</package>
在这里,你是使用Javascript(jQuery的)code:
And here you are the Javascript (jQuery) code:
function loadMarkersJ(){
alert("dentro");
$.ajax({
type : "post",
url : "LoadMarkers",
dataType: "json",
success : function(data) {
alert(data);
var image = new google.maps.MarkerImage ('https://p.xsw88.cn/allimgs/daicuo/20230910/918.png');
var jSon_Object = eval("(" + data + ")");
//For para analizar los datos (Json) obtenidos de la BBDD
for (x = 0; x < jSon_Object.length; x++) {
var markersArray = [];
var myLatlng = new google.maps.LatLng(jSon_Object[x].lat, jSon_Object[x].lon);
markerLoaded = new google.maps.Marker( {
position : myLatlng,
map : map,
icon: image,
title: "NOMBRE: " + jSon_Object[x].tarjetName + "n" + "ANOTACIONES: " + jSon_Object[x].anotaciones + "n" + "TIME: " + jSon_Object[x].time
});
markersArray.push(markerLoaded);
if (markersArray) {
for (i in markersArray) {
alert("entro en forColocaMarkers");
if (markersArray[i].getAnimation() != null) {
markersArray[i].setAnimation(null);
} else {
markersArray[i].setAnimation(google.maps.Animation.BOUNCE);
}
markersArray[i].setMap(map);
}
}
}
}
});
}
在成功:功能(数据){
到最后,是JavaScript的code创建德标记,这没关系。问题是蒙山阿贾克斯,因为我没有得到获得markerList阵列通过JSON数据返回......我觉得这个问题是从$就url属性...我想loadMarkers.action和loadMarkers,但没有发生。当我执行网页,只打印警报警报(迪登特鲁)
,警报警报(数据)
从不已被打印
From success : function(data) {
to the end, is JavaScript code to create de markers, and this it's OK. The problem is whith ajax, because I don't get to obtain markerList Array by jSon data return...I think that the problem is in the url attribute from $.ajax...I tried loadMarkers.action and loadMarkers, but nothing happens. When I execute the web, only prints the alert alert("dentro")
, the alert alert(data)
never has been printed.
我忘了加code,我调用JavaScript函数(loadMarkersJ)。在这里,您是:
I have forgotten to add the code where I call the Javascript function (loadMarkersJ). Here you are:
<p><s:a action="LoadMarkers.action" namespace="/test" onclick="loadMarkersJ(this)">Cargar Marcadores S</s:a></p>
有人能帮助我吗?
Somebody can help me please?
推荐答案
你有没有考虑使用的 Struts2的-jQuery插件它真的简化Ajax开发Struts2的,用它由我自己
Have you consider using the Struts2-jQuery plugin It REALLY simplifies ajax development with Struts2, used it by myself
相关推荐
最新文章