使用Asp.Net Web Services和Json-JQuery。我的代码很简单: 加载aspx页面。单击按钮并调用Web服务。
它在Chrome中完美运行但在IE11中并不适用。即使我在浏览器控制台中执行一个简单的JQuery脚本,比如$(btnguardar),即返回undefined,chrome也会返回按钮。
有解决方法吗?
这是我的代码: (aspx文件)
<%@ Page Title="" Language="VB" MasterPageFile="~/wprincipal.master" AutoEventWireup="false" CodeFile="winicio.aspx.vb" Inherits="winicio" Culture="es-MX" ViewStateMode="Disabled" ClientIDMode="Static" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script src="Script/jquery-1.4.1.js" type="text/javascript" language="javascript"></script>
<style type="text/css">
.style1
{
width: 159px;
}
</style></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<ajaxToolkit:ToolkitScriptManager ID="tsm" runat="server" EnableScriptLocalization="true" EnableScriptGlobalization="true"></ajaxToolkit:ToolkitScriptManager>
<table style="width:100%;">
<tr>
<td class="style1">
Nombre </td>
<td>
<asp:TextBox ID="txtnombre" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td class="style1">
Apellido </td>
<td>
<asp:TextBox ID="Txtapellido" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td class="style1">
Estado </td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Descripcion"
DataValueField="IdEstado">
</asp:DropDownList>
<asp:HiddenField ID="hdfestado" runat="server" />
</td>
</tr>
<tr>
<td class="style1">
Fecha</td>
<td>
<asp:TextBox id="txtfecha" runat="server" ClientIDMode="Static"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="dtpick" runat="server" EnabledOnClient="true" TargetControlID="txtfecha"></ajaxToolkit:CalendarExtender>
</td>
</tr>
<tr>
<td class="style1">
Observacion </td>
<td>
<asp:TextBox id="txtobservacion" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<input type="button" id="btnretroceder" value="<" />
<input type="button" id="btnAvanzar" value=">" />
</td>
<td>
<input type="button" id="btnguardar" value="Guardar" />
</td></tr>
</table>
<asp:HiddenField ID="idcliente" runat="server" />
<script type="text/javascript" language="javascript">
var ax = document.getElementById("txtfecha");
ax.readOnly = true;
var frm = document.getElementById("form1");
if (frm) {
frm.onsubmit = function () { return false; };
}
$(document).ready(function () {
$(btnAvanzar).click(function (event) {
$.ajax({
type: "POST",
url: "wsClientes.asmx/ConsultarClienteJSON",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
AjaxSucceeded(msg);
},
error: AjaxFailed
});
});
});
function AjaxSucceeded(result) {
var datos = eval('(' + result.d + ')');
if (datos) {
document.getElementById("txtnombre").value = datos.Nombre;
document.getElementById("Txtapellido").value = datos.Apellido;
$(DropDownList1).val(datos.IdEstatus);
var a = new Date(Date(datos.FechaCaptura.substring(datos.FechaCaptura.indexOf('(') + 1, datos.FechaCaptura.indexOf(')'))));
document.getElementById("txtfecha").value = a.getDate() + '/' + (a.getMonth() + 1) + '/' + a.getFullYear();
document.getElementById("txtobservacion").value = datos.Observacion;
}
}
function AjaxFailed(result) {
alert(result.status + ' ' + result.statusText);
}
</script>
这是网络服务:
Imports System.Xml
Imports System.Web
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Web.Services.Protocols
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Json
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ScriptService()>
Public Class wsClientes
Inherits System.Web.Services.WebService
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function ConsultarClienteJSON() As String
Dim cls As New Datos.Usuarios.clsClientes
Dim memstr As New IO.MemoryStream
cls.Obtener_Clientes_AProp()
Return Serialize(cls)
End Function
Public Shared Function Serialize(Of T)(obj As T) As String
Dim serializer As New DataContractJsonSerializer(obj.[GetType]())
Dim ms As New IO.MemoryStream()
'serializer.
serializer.WriteObject(ms, obj)
Dim retVal As String = Encoding.Default.GetString(ms.ToArray())
retVal = Encoding.UTF8.GetString(ms.ToArray())
Return retVal
End Function
End Class
由于
答案 0 :(得分:1)
发现
$(btnAvanzar)
chrome和firefox支持。但Internet Explorer需要以下语法
$("#btnAvanzar")
其他方式是
$(document.getElementById("btnAvanzar"))
然而写
需要太多感谢您的合作