Foren
JSON API in 6.1
Sergey B, geändert vor 12 Jahren.
JSON API in 6.1
New Member Beiträge: 15 Beitrittsdatum: 20.11.11 Neueste Beiträge
Has anyone figured out how to use the new JSON API in LF 6.1? After much digging around, I found this addition to web.xml was needed:
I can hit /api/json and see my JSON services exposed, but making a call doesn't return JSON, it turns the HTML for the /api/json page.
<servlet>
<servlet-name>JSON Web Service Servlet</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortalClassLoaderServlet</servlet-class>
<init-param>
<param-name>servlet-class</param-name>
<param-value>com.liferay.portal.jsonwebservice.JSONWebServiceServlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JSON Web Service Servlet</servlet-name>
<url-pattern>/api/json/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JSON Web Service Servlet</servlet-name>
<url-pattern>/api/secure/jsonws/*</url-pattern>
</servlet-mapping>
I can hit /api/json and see my JSON services exposed, but making a call doesn't return JSON, it turns the HTML for the /api/json page.
Liferay.Service.<company>.<object>.<method>({}, function(response) {
alert(response); // the response object is page HTML, not JSON
}
);<br><br>WTF?! It would be so nice if LR kept their APIs backward compatible or at least provided some documentation about changes to existing APIs.</method></object></company>