Returning redirect as response to XHR request

What happens if the browser receives a redirect response to an ajax request? If the server sends a redirect (aka a 302 response plus a Location: header) the redirect is automatically followed by the browser. The response to the second request (assuming it also isn’t another redirect) is what is exposed to your program. In … Read more

Keep p:dialog open when a validation error occurs after submit

The onsuccess runs if ajax request itself was successful (i.e. there’s no network error, uncaught exception, etc), not if action method was successfully invoked. Given a <p:dialog widgetVar=”yourWidgetVarName”>, you could remove the onsuccess and replace it by PrimeFaces RequestContext#execute() inside saveMethod(): if (success) { RequestContext.getCurrentInstance().execute(“PF(‘yourWidgetVarName’).hide()”); } Note: PF() was introduced in PrimeFaces 4.0. In older … Read more

ASP.NET MVC controller actions that return JSON or partial html

In your action method, return Json(object) to return JSON to your page. public ActionResult SomeActionMethod() { return Json(new {foo=”bar”, baz=”Blech”}); } Then just call the action method using Ajax. You could use one of the helper methods from the ViewPage such as <%= Ajax.ActionLink(“SomeActionMethod”, new AjaxOptions {OnSuccess=”somemethod”}) %> SomeMethod would be a javascript method that … Read more

How to cancel/abort jQuery AJAX request?

The jquery ajax method returns a XMLHttpRequest object. You can use this object to cancel the request. The XMLHttpRequest has a abort method, which cancels the request, but if the request has already been sent to the server then the server will process the request even if we abort the request but the client will … Read more

How can I populate a text field using PrimeFaces AJAX after validation errors occur?

The cause of the problem can be understood by considering the following facts: When JSF validation succeeds for a particular input component during the validations phase, then the submitted value is set to null and the validated value is set as local value of the input component. When JSF validation fails for a particular input … Read more