Thursday, October 22, 2009

Client-side Spell Checking with Asp.Net and jQuery

Overview

I couldn't find a client-side spell check that worked with Asp.Net, so I decided to use Brandon Aaron's jQuery plugin, "Spell Check". He gives you an PHP file to handle the request to the Google API, but I don't use PHP on my server, so I had to create the following Asp.Net Generic Handler.

Create a Generic Handler


Copy and paste this into the Generic Handler you just created:
string text, body, lang;

lang = context.Request.QueryString["lang"];

text = HttpUtility.UrlDecode(context.Request.QueryString["text"]);

body = ""
  + ""
   + "" + text + ""
  + "";


WebClient client = new WebClient();
client.Headers.Add("Content-Type", "text/xml");

byte[] buffer = Encoding.UTF8.GetBytes(body);

byte[] response = client.UploadData("https://www.google.com/tbproxy/spell?lang=" + lang, "POST", buffer);

string result = Encoding.UTF8.GetString(response);

context.Response.ContentType = "text/xml";
context.Response.Write(result);

Change the URL

Need to change the url in the jquery.spellcheck.js file (line 44 in Version 0.2-pre):

3 comments:

  1. I just stumbled in here. thanks for the info. Can I still get hold of the google api key, or has it been closed?

    ReplyDelete
  2. Just stopping by and I have a quick question. How would you implement this using your own custom dictionary such as a txt file or something?

    ReplyDelete
  3. This is an excellent post I seen thanks to share it. It is really what I wanted to see hope in future you will continue for sharing such a excellent post. spell to make someone fall in love with you

    ReplyDelete