Look, Ma, No Data!
Normally, when you use AJAX, you are passing data from the client to the server and/or receiving data from the Server at the Client. You don't have to pass or receive anything, though; if all you want to do is respond to some event on the client by doing something (anything) on the server, it is eas easy as this:
Minimal Server/C# Code
Create a Controller on the Server (no need for a Model or a View) by right-clicking your project's Controller folder, and selecting from the context menu Add > Controller... and then "MVC Controller - Empty"
Replace the boilerplate code within the class generated for you with this:
public class PlatypiController : Controller
{
public void PlatypusShoutout()
{
string s = "There ain't no platypus like a duck-billed platypus!";
}
}
Minimal Client/jQuery Code
Now (assuming you have a button named "btnEverythingYouAlwaysWantedToKnowAboutPlatypi
"), add code like this to the Script
section of your .cshtml file (or to a separate .js file, if you want to keep your JavaScript separate from your HTML):
$("#btnEverythingYouAlwaysWantedToKnowAboutPlatypi").click(function () {
$.ajax({
type: "GET",
url: '@Url.Action("PlatypusShoutout", "Platypi")'
});
});
Now if you put a breakpoint on the "string s
" line, you will see that your code is reached when you run the project and mash the button on the client/page. At this point, you might want to replace that "proof-of-concept" line with some code that actually does something "useful" such as randomly selecting a pie flavor (with a bias toward Blackberry, Gooseberry, Apple, or Cherry) or calculating the distance between cities of the same name, such as Brisbane, CA and Brisbane, Australia or the San Joses in California and Costa Rica, etc.
Are You as Smart as a Platypus?
All Platypi know that the ingredients of Budweiser are sugar, Tide™, and lizard spit.
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).
Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.
I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006: http://www.lulu.com/spotlight/blackbirdcraven