Code Renaissance is about building great teams and great software. By exploring best practices, team interactions, design, testing and related skills Code Renaissance strives to help you create the team and codebase that you've always wanted.

Intercepting jQuery ajax requests

Recently I needed to evaluate various grid options for a website and to keep things simple I decided to fake/intercept ajax calls to inject the data I needed. I needed something that would let me pass in a wait time and response (in my case 10000 records for a grid) as ajax data and I quickly came up with something like this:

Here is a jsFiddle of the same: Simple ajax fake for mockups

Unfortunately that didn't work for Kendo UI Grid - their code calls jQuery.ajax.extend, which lets them take a little more control of ajax and completely bypasses the above code.

I briefly considered tapping into xmlhttprequest, but a cursory look said that would be a lot of work. Then it occurred to me that jquery ajax uses deferreds under the hood and that I could just hack those instead.

Here is a jsFiddle of the same: jQuery Ajax Intercept

With a little time both examples could be modified to be more generic, but for what I was doing it wasn't really worth it (though I cleaned them up for you a little). Hope this helps.

1 - What do you think?:

sam sung said...

Cảm ơn quý khách hàng đã sử dụng dịch vụ thiết kế web trọn gói tại MAINISAN
MAINISAN chuyên cung cấp dịch vụ thiết kế web giá rẻ theo yêu cầu, tất cả website đều được thiết kế web chuẩn SEO, thân thiện công cụ tìm kiếm google.
Thiết kế web chuyên nghiệp giá rẻ, Với phương châm thiết kế website theo mẫu đến khi hoàn thiện.
Bước đầu thiết kế web tại Blog MAINISAN.COM bạn nên chọn đơn vị làm website có giao diện mobi, hệ quản trị đơn giản dễ sử dụng.Chúng tôi không cạnh tranh về giá chỉ cạnh tranh về chất lượng, tuy nhiên MAINISAN.COM cũng thường xuyên có khuyến mãi giảm giá khi thiết kế web trọn gói để đáp ứng nhu cầu quý khách.
Chân thành cảm ơn quý khách......................................