Showing all posts tagged: 'JavaScript'

A 22-post collection

An introduction to JavaScript Unit Testing with qUnit and Sinon.js

If you are developing for the web – apps or websites, then it is almost impossible to escape JavaScript. At some point, you will write some client-side code and as the application grows and the requirements become more complex, your JavaScript code is bound to grow with it. Like with every other complex piece of code, we need to be confident that the code behaves as expected. It doesn’t matter if you decide to use TDD or not, what’s important is to test your code. You can do this manually, very tedious and error prone, or programmatically. The choice …[read more]


Importing CSV files using jQuery and HTML5

One of the cool features of HTML5 is the new File API that allows the broswer to directly interact with files on the file system. Most modern browsers that support HTML5 can use this API to perform client-side only processing without the need for a round trip to the servers or the use of ajax etc. In effect the server becomes redundant and the user experience more fluent and responsive. You can still, if you need to, perform server-side processing, but if you only want to make the file contents available to the browser then you can use the code …[read more]


Getting Json data using jQuery and .ASMX web services.

If you still have the misfortune to work with asmx services on your project, you may want to know how to easily retrieve json data from an asmx method. The differences between asmx and WCF have been aalyze[d b]efore here and here. Return a simple string as json response:### Your asmx page code#### [WebService(Namespace = "http://contoso.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]System.Web.Services.WebService [ScriptService] public class services :WebService { [WebMethod(CacheDuration = 60)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string GetGreeting() { return "hello world" } } Your javascript code#### …. code omitted … var getGreeting = function() { var …[read more]


Working with Radio buttons and jQuery

Working with Radio buttons and jQuery Radio buttons are one of the essential HTML elements that you can find in almost any website that contains a form for users to enter data. In this blog today we will do the following: Add radio buttons dynamically using jQuery And, get the value and text of the selected radio button using jQuery First you need a standard boiler plate html page that has a reference to the jQuery library. For this example we will use the Google jQuery CDN to pull the library on our page. At this stage, you page should …[read more]


Accessing local data files using Html and Chrome

During the development and testing stages of a new website, there are time when you may need to access Json or xml data stored in a local file. The test site can be running under Visual Studio, IIS Express or even IIS. I recently had to quickly test some javascript code that interacted with Json data. I was trying to debug using Chrome's Developers tools but I was getting an error at every execution. The method was doing nothing more than this: $.getJSON('file:///C:/Temp/testdata.json' By default, Chrome does not allow javascript  to interact with local file …[read more]


Uncaught Type Error: Object [object Object] has no method '' – jQuery Error

Many developers have been caught up by this error message judging by the number of posts on StackOveflow! I had to spend a few hours with this exception until finding the solution. Now I know that writing code while tired is never a good thing! The problem started when I tried to integrate the FileDrop jQuery plugin to my MVC 4 project. After adding all the files and JavaScript code, I was greeted by this perplexing error message: Object [object Object] has no method.. This error, in most cases, means that jQuery is not working and no such function can …[read more]