Skip to main content

Posts

Showing posts from August, 2015

Add custom http header to all jQuery AJAX Requests

A pre-filter would be an easy way of accomplishing this: $ . ajaxPrefilter ( function ( options ) { if ( ! options . beforeSend ) { options . beforeSend = function ( xhr ) { xhr . setRequestHeader ( 'CUSTOM-HEADER-KEY' , 'CUSTOM-HEADER-VALUE' ); } } }); this way all requests will get the custom header, unless the specific request overrides the beforeSend option. Note however you can accomplish the same goal using ajaxSetup. the only reason that warning is there is because using it will affect all ajax requests (just like my method will), possibly resulting in unwanted results if a specific request didn't need that option set. I'd suggest just using ajaxSetup, that is what it's there for after all. ---------------------------------------------------- You can use the ajax global event   ajaxSend() $ ( document ). ajaxSend ( function ( event , jqxhr , settings ) { jqxhr . setRequestHeader...

Getting the Starting and ending date in sql

--StartDate and EndDate of Week  SELECT  DATEADD(DAY, 1 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE)) [WeekStart],         DATEADD(DAY, 7 - DATEPART(WEEKDAY, GETDATE()), CAST(GETDATE() AS DATE)) [WeekEnd] --StartDay and EndDay of Month SELECT  DATENAME(WEEKDAY, DATEADD(DAY, 1 - DATEPART(DAY, GETDATE()), GETDATE())) [FirstDayOfMonth],         DATENAME(WEEKDAY, DATEADD(DAY, - DATEPART(DAY, DATEADD(MONTH, 1, GETDATE())), DATEADD(MONTH, 1, GETDATE()))) [LastDayOfMonth]