好吧,我正在尝试使用jquery和ajax从PageMethod中检索信息,到目前为止我还没有运气
在调整整个事情的同时,我发现我的错误部分正在启动,然后我使用VS的调试器并没有得到任何信息,但是使用Firebug我发现该方法未找到,给出内部服务器错误被扔了
这是我的aspx代码
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="RutaLecturista.aspx.vb" Inherits="LocalLecturas.RutaLecturista" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ruta Lecturista</title>
<link type="text/css" href="../Estilo.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
var map;
var trazoRuta = new Array();
$(document).ready(function()
{
inicializar();
});
function inicializar()
{
var latlng = new google.maps.LatLng(29.082807, -110.928197);
var myOptions =
{
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
extraerDatos();
}
function extraerDatos()
{
$.ajax({
type: 'POST',
url: 'RutaLecturista.aspx/obtenerCoordenadas',
data: '{}',
contentType : "application/json; charset=utf-8",
dataType: 'json',
succes: function(xml)
{
crearMarca(xml);
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
alert('Error al consultar el servicioWeb: ' + errorThrown + ' ' + textStatus + ' ' + XMLHttpRequest);
$("#errmsg").ajaxError(function(event, request, settings)
{
$(this).append("<li>Error al extraer los datos " + settings.url + "</li>");
});
}
});
}
function crearMarca(xml)
{
try
{
alert('Datos obtenidos!!!');
$(xml).find('Table').each(function()
{
var lat = $(this).find('Latitud').text();
var lon = $(this).find('Longitud').text();
var certeza = $(this).find('Precision').text();
var titulo = $(this).find('F_Actual').text();
var location = new google.maps.LatLng(lat, lon);
trazoRuta.push(location);
var marker = new google.maps.Marker(
{
position: location,
map: map
});
marker.setTitle(titulo);
var circuloCerteza;
google.maps.event.addListener(marker, 'mouseover', function()
{
var populationOptions =
{
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35,
map: map,
center: location,
radius: certeza / 2
};
circuloCerteza = new google.maps.Circle(populationOptions);
});
google.maps.event.addListener(marker, 'mouseout', function()
{
circuloCerteza.setMap(null)
});
});
trazoRuta.reverse();
var ruta = new google.maps.Polyline(
{
path: trazoRuta,
strokeColor: "#FF0000",
strokeOpacity: 1.0,
strokeWeight: 2
});
ruta.setMap(map);
}
catch(err)
{
}
}
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++)
{
var pair = vars[i].split("=");
if (pair[0] == variable)
{
return pair[1];
}
else
{
return "";
}
}
}
/*function crearMarca(titulo, lat, lon, certeza)
{
var location = new google.maps.LatLng(lat, lon);
var marker = new google.maps.Marker(
{
position: location,
map: map
});
marker.setTitle(titulo);
var circuloCerteza;
google.maps.event.addListener(marker, 'mouseover', function()
{
var populationOptions =
{
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35,
map: map,
center: location,
radius: certeza / 2
};
circuloCerteza = new google.maps.Circle(populationOptions);
});
google.maps.event.addListener(marker, 'mouseout', function()
{
circuloCerteza.setMap(null)
});
} //*/
</script>
</head>
<body>
<div id="map_canvas" style="width:50%; height:50%"></div>
<form id="form1" runat="server">
<div id="errmsg" style="width: 244px">
<asp:Label ID="Label_1" runat="server">No hay Coordendas para esta Ruta</asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<%-- <asp:GridView ID="gvCoordenadas" runat="server" AutoGenerateColumns="False" CellPadding="4"
GridLines="None" CssClass="REPORTE">
<FooterStyle CssClass="REPORTE_FooterStyle" />
<RowStyle CssClass="REPORTE_RowStyle " />
<Columns>
<asp:BoundField DataField="Latitud" HeaderText="Latitud" />
<asp:BoundField DataField="Longitud" HeaderText="Longitud" />
<asp:BoundField DataField="F_ACTUAL" HeaderText="Fecha" />
</Columns>
</asp:GridView>
--%>
</div>
</form>
</body>
</html>
这是codeBehind代码
Partial Public Class RutaLecturista
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If Session("USR") = Nothing Then
' Response.Redirect("../Acceso.aspx?dato=No tiene acceso en este sistema")
'End If
Response.Write("<script type=""text/javascript"" src=""http://maps.google.com/maps/api/js?sensor=false""> </script>")
'Dim sb As New System.Text.StringBuilder()
'sb.Append("<script language=""javascript"" type=""text/javascript"">")
'Try
' Dim id_lec As String = Request.QueryString("id_lec").Substring(0, 10)
' Proceso.Fill_DataSet(DataSet, Consultas.obtenerLocalizacion(id_lec, "", "", ""), "Coordenadas" + id_lec)
' If DataSet.Tables("Coordenadas" + id_lec).Rows.Count > 0 Then
' Label_1.Visible = False
' gvCoordenadas.DataSource = DataSet.Tables("Coordenadas" + id_lec)
' gvCoordenadas.DataBind()
' gvCoordenadas.Visible = True
' sb.Append("function crearMarcas(){" + vbNewLine)
' For Each linea As Data.DataRow In DataSet.Tables("Coordenadas" + id_lec).Rows
' sb.Append("crearMarca(""" + linea("F_Actual").ToString + """, " + linea("Latitud").ToString + ", " + linea("Longitud").ToString + ", " + linea("precision").ToString + ");" + vbNewLine)
' Next
' sb.Append("}" + vbNewLine)
' sb.Append("var trazoRuta = [" + vbNewLine)
' For contador As Integer = 0 To DataSet.Tables("Coordenadas" + id_lec).Rows.Count - 1
' sb.Append("new google.maps.LatLng(" + DataSet.Tables("Coordenadas" + id_lec).Rows(contador).Item("Latitud").ToString + ", " + DataSet.Tables("Coordenadas" + id_lec).Rows(contador).Item("Longitud").ToString + ")")
' If contador + 1 < DataSet.Tables("Coordenadas" + id_lec).Rows.Count Then
' sb.Append("," + vbNewLine)
' End If
' Next
' sb.Append("];" + vbNewLine)
' Else
' End If
'Catch ex As Exception
'End Try
'sb.Append("</script>")
'ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ajax", sb.ToString(), False)
End Sub
<System.Web.Services.WebMethod()> _
Public Function obtenerCoordenadas() As String
Dim datos As New Data.DataSet
Dim resultado As String = ""
Dim id_lec As String = Request.QueryString("id_lec").Substring(0, 10)
Proceso.Fill_DataSet(datos, Consultas.obtenerLocalizacion(id_lec, "", "", ""), "Coordenadas" + id_lec)
If DataSet.Tables("Coordenadas" + id_lec).Rows.Count > 0 Then
resultado = datos.GetXml
End If
Return resultado
End Function
End Class
希望我能快速得到答案,我已经没有时间,耐心和想法:S
答案 0 :(得分:0)
您需要将obtenerCoordenadas()
方法设为静态。
<System.Web.Services.WebMethod()> _
Public Shared Function obtenerCoordenadas() As String
Dim datos As New Data.DataSet
Dim resultado As String = ""
Dim id_lec As String = Request.QueryString("id_lec").Substring(0, 10)
Proceso.Fill_DataSet(datos, Consultas.obtenerLocalizacion(id_lec, "", "", ""), "Coordenadas" + id_lec)
If DataSet.Tables("Coordenadas" + id_lec).Rows.Count > 0 Then
resultado = datos.GetXml
End If
Return resultado
End Function
这是Dave Ward关于这个话题的精彩文章。
http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/