Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!