Sunday, November 14, 2010

AJAX with jQuery in ASP.Net

There are already a whole bunch of blogs out there on this subject by people much more qualified for the task. I'm just trying to compile my own efforts to preform an AJAX call on a ASP.Net page to a method in the page's code-behind in one place. There are enough quirks for me to know I'd have to look things up in the future so might as well just put it all in one place and make it available for anyone else who might want this info.

Microsoft's CDN link for the jQuery library (current release at the time of writing)

Reference it in the head of your page like this:

With jQuery, when the page is ready for manipulation (loaded except for images) add a click event handler to a button with id="btnServerCall"
$(document).ready(function () {
$("#btnServerCall").click(function (event) {
//This prevents the event from propagating further
event.preventDefault();

//TODO: Event handler code goes here
});
});

Now lets setup the server side method that we want to call. There is a requirement that the method be static (C#) or shared (VB) and marked with the WebMethod attribute. This prevents you from working with anything else that is outside of the scope of the method but this isn't anything new to async stuff. Also make sure you have System.Web.Services referenced as this method will be called just like a web service by jQuery. My method looks like this:
[WebMethod()]
public static string ServerGreeting(string userName)
{
return ("Hello " + userName).Trim() +
"! The current server time is: " +
DateTime.Now.ToString();
}

Now for the jQuery AJAX call which will be the event handler code added to the first chunk of code
$.ajax({
type: "POST",
url: "jQueryTest.aspx/ServerGreeting",
data: "{'userName': '" + $('#txbName').val() + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
},
error: function(result) {
alert(result.status + ' ' + result.statusText);
}
});

If you're wondering what that business with the success and error parameters is all about, those are anonymous methods that are going to be called on the completion of the call to the server and depending on the success or failure of it.

That's pretty much it. I went heavy on the code and light on the explanation as this is really meant to be a reference and not a tutorial.

I got almost all of this from http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx which covers way more material then I did here and gives a lot more explanation. I just extracted out what I needed to preform an AJAX call.

If you want to read more about jQuery, http://jquery.com/ is the the place to go.

Wednesday, July 7, 2010

Assumptions about AI

Here is an Essay by a, seemly, smart and well educated person on Search and AI: http://blog.steinberg.org/?p=11

It's a long read but interesting if you're up for it. That being said I want to comment and disagree with two things that were said in the last section titled "Coda".

1) "AI does teach us about intelligence. It teaches us that “intelligence” is a motley assortment of heuristics, kludges, and cheap tricks." I wanted to point out that he seems to be making a fatal assumption; because we have solved problems that were considered to be in the domain of AI and the solutions to those problems were "a motley assortment of heuristics, kludges, and cheap tricks," a true general AI (Strong AI) will look the same, and therefore that's all our intelligence is. The author pokes a bit of fun at other people who have made grand claims and predictions about AI but then he himself goes and does the same thing. The truth is we really don't have a good idea about what a real general artificial intelligence will look like and based on the lack of progress I'd guess the chances of deriving a solution from known methods aren't good.

2) "If we were trying to build a true, general AI, we would first need to create a way for it to get around and interact with the larger world." This is another instance of the irritatingly pervasive idea that we need to have an AI acting in the real world with a real "body". I can not understand why some people see this as so crucial. To me it seems to do nothing but add a whole lot of unnecessary complications to an already very hard problem.

Assumptions like these are never going to get us to a general AI. People need to stick to observable facts, make theories based on them, and then test those theories.

Friday, May 28, 2010

Disputing John Searle's Chinese Room

I often hear people claiming Artificial Intelligence (AI) is not possible to create as proven by John Searle's Chinese Room argument. The details of that argument can be found here: http://en.wikipedia.org/wiki/Chinese_room. This argument has always seemed flawed to me but I could never quite put my finger on why until yesterday.

While reading yet another claim that AI is not possible as demonstrated by the Chinese Room it occurred to me that there is a fundamental assumption in the argument that is completely flawed. This assumption is that you can have an algorithm that appropriately responds to prompts given in a natural language without being intelligent. This is illogical. An algorithm is just a set of instructions to solve a problem. It's predetermined. It is not intelligent, it may exibit intelligence because it is the product of intelligence but it has no intelligence its self. I think this is John Searle's real point. If that's the case then we agree, algorithms are not intelligent even though they can exhibit intelligence.

Responding to prompts given in a natural language such as Chinese, English, etc. requires intelligence. This is due to the fact that intelligent beings create, maintain, and evolve natural languages for the purpose of communicating thoughts and ideas with each other. Words are added modified or discarded based on the common thoughts of a population of intelligent beings. Therefore something without intelligence will never be able to communicate correctly using a natural language because the language is always changing due to the intellectual evolution of a population. There is probably a much better proof for this so if this is the one point that people want to argue about I'm confident this can be proven to most peoples' satisfaction.

Now to my main point, the problem with the Chinese Room is that John Searle has used a contradiction as an assumption to base his arguments on. I think most people are familiar with the outrageous proofs that can be made when the proof starts with an assumption of 1=0, such as "I am the Pope". This is exactly what Mr. Searle has done. He has in effect said, "Take this thing that is not intelligent and assume it is doing something that requires intelligence." Once that assumption is made you can prove pretty much anything you want. The most obvious proof is, "There is no intelligence."

Monday, June 8, 2009

Bing vs. Google

I switched my default search engine to Bing, Microsoft's new search engine, about a week ago. I'm used to finding pertinent results to most of my searches with google in the first page and usually the first few links. So my rule for Bing was, if it's not on the first page I'd go to Google and see how it worked there. I just wanted to give a quick report of my experience so far.

For the most part Bing seems to do just fine. I haven't really seen any advantage to it over Google but the rumor is it's supposed to be better for media and perhaps a few other things. I'd say 1 out of every 5 queries I do on Bing I'm not satisfied with the results and so I try Google. Out of those 1/5 I'd say Google gives me what I'm looking for about 2/3 of the time. These are very rough numbers of course, completely off the cuff, but for now it's the best I can do.

Here are a few samples from those 20% that Bing didn't do the job for me (They are pulled out of my twitter so keep that context in mind):

Google beats bing for map search of "rattlesnake creek, covelo, ca". Google nailed it. Bing didn't get close.

RT @pmdorn: @mmadink I crashed Bing! I searched for Google! LOL

Google wins Bing for "add twitter to blogger"

google beats bing for the query "What is a twibe"

And here's a few to give Bing a bit of a moral boost:

Bing did the job for "What is JEE"

Bing beat Google for "google app engine manager". Pretty funny that Bing did a better job then Google for Google's own product.

I've been playing around with Google's web development tools (very cool by the way) and I couldn't find the home page for their App manager. Google would NOT give it to me. Gave Bing a try and it got it on the first page. That's a good example of why competition is good. I love Google but everyone needs some good healthy competition to keep them honest.

So at this point I think it's actually up in the air as to which is actually better. Google obviously has a leg up but Bing is brand spanking new and with that in mind I'm pretty impressed with it. I haven't changed me default search engine back to Google yet either. I will as soon as Bing starts to slow me down.

Tuesday, June 2, 2009

User Interfaces

There is a blog here: http://blogs.zdnet.com/hardware/?p=4467 that discuses users moving from Windows XP, the primary windows user base, to Windows 7. As with almost anything that discuses Windows where user comments are allowed a flame war started. Normally I just skip over these but I found the subject of this one very intriguing; Microsoft and it's constant changing of the user interfaces (UIs), good or bad?

Some very interesting points were actually made in between the insults being thrown back and forth and I'll try to present both sides of the argument.

Side A; Unless there is some ground-breaking change to a UI that will add significant advantages over the current one, it shouldn't be changed at all due to the cost and trouble of users having to relearn how to do things (like open a file). Most users are just trying to get their job done and using a computer is a means to that end, nothing more. Unless there is a better way to do their job they shouldn't have to relearn how to do it. Period.

Side B; Technology changes and interfaces change with them. Users should expect to have to familiarize themselves with a new UI for a piece of technology in the same way they would have to, and be expected to, familiarize themselves with new controls for a vehicle. Say going from a '70 Chevy to a '09 Prius. It's also likely that the UI hasn't changed much unless there really is new functionality that the old interface wouldn't support. It really probably just looks a bit different and once you look past the new colors and graphics you'll see it's mostly the same.

My Take; I'm not agreeing and disagreeing with either of them. I definitely think changing the UI for no good reason is really annoying and I myself get irritated every time I find something that I used to know right where it was has moved. On the other hand I'm a developer and I actually have to make the call to change the UI at times. I've experienced first hand the ridiculous lash-backs from users about having to learn a new interface that I know is better. I've also seen first hand that it's only a few users that really seem to have a problem. Out of my 2500 users of this small application that I drastically changed the interface on (because the old one wouldn't support new features) I had about ten users call and complain. Out of those ten, one called back repeatedly and accounted for about 98% of the complaints.

So what's the point of this post if I'm not going to take a side? It's just to ask people to be aware that UIs do have to change sometimes to move things along. This isn't always the case and users have a right to be annoyed when they get changes for PR purposes but before you flame your developers please take a few extra seconds to see if there really is some benefit to the annoying new UI.

Monday, March 2, 2009

VS 2003 Server Extension Snafu

Recently I started to convert a virtual terminal server to a development machine so I don't have to worry about my machine dieing on me, leaving me unable to work while it is getting fixed.  Believe it or not I've been through three machines in the last 2 years.  I swear it's not my fault.  My cube is cursed.  Anyway that is why I'm off loading my development environments to a virtual server. 

One of my jobs at work is maintaining a whole bunch of ASP.Net 1.1 projects.  Unfortunately, after installing Visual Studio 2003 it would not open any of the ASP projects.  It would always give the error, "cannot find the components for communicating with the frontpage server extensions".  It wouldn't even let me make a new one but that was helpful since I new it had to be something with the server and/or the install.  I fiddled with it for a few hours then gave up since I could still open and work on them locally.  Then after a few weeks I asked another more experienced guy to look at the problem.  He couldn't get it either.  I finally found the solution here:

http://blogs.geekdojo.net/brian/archive/2004/04/23/WebProjects.aspx

which basically says; Run msiexec.exe /x {17B66E83-1BC9-11D5-A54A-0090278A1BB8}
Then reinstall the prerequisites. 

It worked.  Thank God.  What a pain.
Blogged with the Flock Browser

Thursday, February 26, 2009

Yahoo has a new CEO

Yahoo's new CEO tried to rally the troops around her new management structure. Here's the full text of her memo to staff.

View Original Article


Yahoo who?  Alright I admit I know who Yahoo! is but to be honest they went from my homepage, primary email and secondary search engine to a company that I forget exists sometimes in less then a year.  That whole fiasco with Microsoft last year really killed them IMHO.  Bartz, Yahoo!'s new CEO, really has her work cut out for her to try and turn things around. 

Oh and as an aside, Flock makes it seductivly easy to blog about stuff.

Blogged with the Flock Browser