anti-CSRF token and Javascript

There are several techniques, which when used together provide a sufficient CSRF protection. Unique Token A single, session-specific token is good enough for most applications. Just make sure that your site doesn’t have any XSS vulnerabilities, otherwise any kind of token technique you employ is a waste. AJAX call to regenerate the token is a … Read more

Ajax update doesn’t work, when using filter on p:dataTable

After updating datatable you have to invoke it’s client side filter() method. <p:dataTable widgetVar=”dataTableWidgetVar” id=”dataTable” var=”row” value=”#{bean.value}” filteredValue=”#{bean.filteredValue}” paginator=”true” rows=”25″ paginatorPosition=”bottom” rowKey=”${row.id}” editable=”true”> <p:commandButton value=”Save” actionListener=”#{bean.save}” update=”:form” oncomplete=”PF(‘dataTableWidgetVar’).filter()”/> For PrimeFaces versions older than 5, you should use <p:commandButton value=”Save” actionListener=”#{bean.save}” update=”:form” oncomplete=”dataTableWidgetVar.filter()”/>

Does JSONP require server modifications?

Yes, JSONP is slightly different when it renders, so your server needs to support it. JSON looks like this: { “name”: “value” } Whereas JSONP looks like this: functionName({ “name”: “value” }); If whatever you’re using supports it you’re covered, but it’s not the same as supporting just JSON. When the server gets a request, … Read more

Can I return custom error from JsonResult to jQuery ajax error method?

You could write a custom error filter: public class JsonExceptionFilterAttribute : FilterAttribute, IExceptionFilter { public void OnException(ExceptionContext filterContext) { if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) { filterContext.HttpContext.Response.StatusCode = 500; filterContext.ExceptionHandled = true; filterContext.Result = new JsonResult { Data = new { // obviously here you could include whatever information you want about the exception // for example if you … Read more

AJAX content in a jQuery UI Tooltip Widget

Here is a ajax example of jqueryui tootip widget from my blog.hope it helps. $(document).tooltip({ items:’.tooltip’, tooltipClass:’preview-tip’, position: { my: “left+15 top”, at: “right center” }, content:function(callback) { $.get(‘preview.php’, { id:id }, function(data) { callback(data); //**call the callback function to return the value** }); }, });

What are the advantages of using a GET request over a POST request?

I generally set up the question as thus: Does anything important change after the request? (Logging and the like notwithstanding). If it does, it should be a POST request, if it doesn’t, it should be a GET request. I’m glad that you call POST requests “slightly” more secure, because that’s pretty much what they are; … Read more

Stop the browser “throbber of doom” while loading comet/server push iframe

After digging for a day and a night in the guts of the internets, here is what I came up with: server-sent events – Very cool, currently works only in Opera, but may be part of HTML5 and other browsers may support it sometime. Adds a new element tag with content-type of “application/x-dom-event-stream” which allows … Read more

In javascript, how can I uniquely identify one browser window from another which are under the same cookiedbased sessionId

you could set your own window name, the exact syntax escapes me right now, but you can use the current time and session id to create a unique id on window load, then use that id This would be done the same way you set a name in the javascript window.open() function, (but you can … Read more