Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
no se puede leer la propiedad de indefinido (leyendo 'ajax')

No puedo acceder al método web dentro de javascript. Da el error en el título. ¿Por qué puede ser causado?

j:

 function funcGoster() { $.ajax({ type: "POST", url: "/WebService1.asmx/HelloWorld", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { // document.getElementById('text').innerHTML = }, error: function (e) { alert("başarısız" + e); } }); } </script>

Método web:

 public class WebService1 : System.Web.Services.WebService { [WebMethod] public static string HelloWorld() { return "Hello World"; } }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ok, lo que tiene se ve bastante bien, pero tenga en cuenta que en la página del servicio web, debe quitar el comentario de una línea.

Entonces, deberías tener esto:

 { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } } }

Ok, ahora nuestro código y marcado:

 <asp:Button ID="Button1" runat="server" Text="Button" Width="153px" OnClientClick="ajtest();return false;"/> <br /> </div> <script> function ajtest() { $.ajax({ type: "POST", url: "/WebService1.asmx/HelloWorld", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { alert(' back from ajax message = ' + msg.d) }, error: function (xhr, status, error) { var errorMessage = xhr.status + ': ' + xhr.statusText alert('Error - ' + errorMessage) } }); } </script>

Entonces, ¿también asumimos que tiene la configuración de jQuery para esta página? Usted necesita que. Puede llamar al método web sin jQuery.

Entonces, JavaScript puro, podrías usar esto:

 // Web method call without jQuery function ajtest2() { // ajax call without jquery var xhr = new XMLHttpRequest() xhr.open('POST', '/WebService1.asmx/HelloWorld') xhr.setRequestHeader('Content-Type', 'application/json') xhr.send('{}'); xhr.onload = function () { if (xhr.status === 200) { var userInfo = JSON.parse(xhr.responseText) alert(' back form ajaxes message = ' + userInfo.d) } } }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda