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

216
Views
Pasar JSON a aspx webmethod 500 Error interno del servidor

Estoy tratando de aprender JSON y jQuery y antes de profundizar en algo demasiado complejo, pensé en probar un ejemplo simple para ponerme al día.

Tengo un botón que, cuando se hace clic, me gustaría pasar un objeto JSON a un WebMethod, realizar algunas operaciones de cadena en él y volver al lado del cliente.

Sin embargo, cuando hago clic en el botón, no sucede nada, la consola del navegador muestra el siguiente error:

POST http://localhost:53388/myfolder/foo/aspx/setrecord 500 (Error interno del servidor)

cualquier ayuda será apreciada

jQuery

 $('#SaveButton').click(function () { var jsonObj = { "data":[{ "id": 1, "name": "Zippy" }, { "id": 2, "name": "George" }, { "id": 3, "name": "Bungle" }, { "id": 4, "name": "geoffrey"}] } jsonObj = JSON.stringify(jsonObj); SaveNewOrder(jsonObj); }) function SaveNewOrder(jsonObj) { $.ajax({ type: "POST", url: "foo.aspx/setrecord", data: jsonObj, contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function (response) { alert(response.d); } }); } function OnSuccess(response) { $('#OutputDiv').html(response.d); }

Clases y WebMethod

 public class ListOfDestinationColumns { public List<DestinationColumn> data { get; set; } } public class DestinationColumn { public int id { get; set; } public string name { get; set; } } [WebMethod] public static string setrecord(string jsonObj) { ListOfDestinationColumns Destinations = new JavaScriptSerializer().Deserialize<ListOfDestinationColumns>(jsonObj); string output = "Start<br/>"; foreach (var item in Destinations.data) { output += string.Format("id: {0}, name: {1}<br />", item.id.ToString(), item.name); } output += "End"; return output; }
about 4 years ago · Santiago Trujillo
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!