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."