Skip to content

Posts tagged ‘ajax’

29
Mar

JSON / Ajax in Spring MVC

How do you configure your Spring MVC web application to serve JSON for Ajax? It is not difficult. You probably have a view resolver in your dispatcher-servlet.xml that looks like this:

<bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:viewClass="org.springframework.web.servlet.view.JstlView"
        p:prefix="/WEB-INF/jsp/"
        p:suffix=".jsp"></bean>

In order to serve JSON content, you need to use the ContentNegotiatingViewResolver. The configuration looks like this:
Read moreRead more

22
Feb

Validate that URLs exist using jQuery / PHP

It would be nice to have a pure javascript method of validating that URLs exist.  One imagines you could use an AJAX call and verify the HTTP status code (200, 404, etc.) returned.  However, browser security does not permit cross-domain AJAX calls.  So, this method would only work if you are validating that URLs exist on the same domain.

Perhaps there is a way to use a hidden iframe to test the existence of a URL.  I am not aware of a way to get the HTTP status code of a page that loads inside of an iframe, though.  I’m not sure it is possible.  So you must rely on javascript plus a server-side programming language to perform this validation.  I chose jQuery and PHP.

Read moreRead more