Thursday, June 18, 2015

TypeError: $.browser is undefined

just put the $.browser code in your js
var matched, browser;

jQuery.uaMatch = function( ua ) {
    ua = ua.toLowerCase();

    var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
        /(webkit)[ \/]([\w.]+)/.exec( ua ) ||
        /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
        /(msie) ([\w.]+)/.exec( ua ) ||
        ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
        [];

    return {
        browser: match[ 1 ] || "",
        version: match[ 2 ] || "0"
    };
};

matched = jQuery.uaMatch( navigator.userAgent );
browser = {};

if ( matched.browser ) {
    browser[ matched.browser ] = true;
    browser.version = matched.version;
}

// Chrome is Webkit, but Webkit is also Safari.
if ( browser.chrome ) {
    browser.webkit = true;
} else if ( browser.webkit ) {
    browser.safari = true;
}

jQuery.browser = browser;

Monday, April 13, 2015

Http handler call from jquery

Generally webmethod call from jquery is very simple and it can be done via following code:
 $.ajax({ type: "POST",
                    url: "Page.aspx/GetDates",
                    data: '{para1:"' + para1Value + '",para2: "' + para2Value + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        alert(response.d);
                    },
                    failure: function (response) {
                        alert(response);
                    }
                });



But same above code will not work in case of httphanlder call. I have found few reasons behind this:
In httphandler we are getting data in form of Request.Params(eg. Request.Param["para1"]) which only supports url encoded data. So json posted data will not work in above code.
So following code can be used instead of above:

$.ajax({
                  type: "POST",
                  url: "Handler.ashx",
                  data: { fName: firstName },
                 // dataType: "json",

                   beforeSend: function (xhr, settings) {
                      //$("[id$=processing]").dialog();
                      alert('st');
                  },
                  success: function (msg) {
                      alert(msg);
                      alert(msg.d);
                  },
                  error: function () {
                      alert("Error");
                  }

              });


See difference no content type and no data type. Thats it!

Tuesday, November 4, 2014

Clean webform cache.

Generally webforms get data from cache while click on browser back button. Following code snippet will cleanout the page cache and doesn't display any previous data even clicking on browser back button.

 Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
        Response.Cache.SetNoStore();
        Response.AppendHeader("Pragma", "no-cache");