Wednesday, May 28, 2014

jQuery AJAX - Purposefully POST no parameters using JSON contentType

My issue: Purposefully execute a .NET WebMethod via POST without passing it parameters.  I use $.ajaxSetup to configure my page's calls, so I'm assuming this is where my snag came up, but I didn't want to have to work around this and make my $.ajax() calls more verbose.

Simple answer: encode an empty JSON object, and it won't be passed to the WebMethod when contentType is JSON.


Visual Studio and Javascript Intellisense

I don't know why I didn't track this down earlier, but as I was coding some jQuery AJAX today, I thought to myself, why isn't there Intellisense for jQuery? I mean, MS supports a whole plethora of other items, including Python, so why not js? Well it seems I just didn't do a quick Google search to find out about the ~/Scripts/_references.js file.

_references.js

It's really simple, you just add references to your js files in this folder of the format:

/// <reference path="jquery-1.10.1.js" />

And voila, I have intellisense.  And if you're really lazy you can simply 
  • right-click this file --> 
    • "Auto-sync Javascript references"
    • "Update Javaascript references"
And anytime you add or remove a file, this reference is updated.

Sources:
http://madskristensen.net/post/the-story-behind-_referencesjs
http://www.asp.net/visual-studio/overview/2012/visual-studio-2012-javascript-editor

Tuesday, May 20, 2014

Python-like loops in C#

I just stumbled across this today as I was looking to use Enumerable.Range():

You can use Enumerable.Range(start, end), close to Python's own Range function.  For instance this should look familiar:

C#

Python

Friday, May 16, 2014

Disable Chrome's Notification Icon

I stole this from a forum, to re-post here.

1. In the Chrome address field, type: chrome://flags

2. On the page that loads up, scroll down until you see "Enable Rich Notifications Mac, Windows", and select "Disabled"