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

156
Views
Cómo obtener datos JSON sin procesar usando la llamada Struts2 Ajax

Obtengo una respuesta [object Object] en la consola mientras espero un JSON completo.

Según mi clase de acción:

 public String getDensityData(){ SessionFactory sf = (SessionFactory) ctx.getAttribute("SessionFactory"); ProductDAO product = new ProductDAOImpl(sf); List<DensityGroup> densityList = product.getDensity(); Gson gson = new Gson(); densityjson = gson.toJson(densityList); System.out.println("JSON: "+densityjson); return "success"; }

Struts.xml

 <package name="json" namespace="/" extends="json-default"> <action name="getJSON" class="com.bmm.action.ProductAction" method="getDensityData"> <param name="noCache">true</param> <param name="excludeNullProperties">true</param> <param name="root">densityjson</param> <result name="success" type="json">/product_master.jsp</result> </action> </package>

JSP:

 $.ajax({ type: "POST", url: '<s:url namespace="/" action="getJSON"/>', data: "json", success: function(data){ console.log(""+data); } });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si espera obtener JSON de la respuesta, debe dataType una propiedad de tipo de datos. JSON es un Object de JavaScript, si necesita imprimirlo, use JSON.stringify() .

 $.ajax({ type: "GET", url: '<s:url namespace="/" action="getJSON"/>', dataType: "json", success: function(data){ console.log(JSON.stringify(data)); } });
about 4 years ago · Santiago Trujillo 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!