Using MochiKit doXHR
The doXHR() function in MochiKit is pretty handy for doing AJAX FORMs. It is a shorthand function for do XMLHttpRequest. Here is some basic usage of doXHR(). I was using this code to save position of a Google Map marker via AJAX POST. The URL called returns a string that gets stuffed into responseText of the result object.
saveMapLocation: function( ) {
//values that i am passing are latitude and longitude
var qry = queryString({lat:latitude.value,lon:longitude.value});
var d = doXHR(url,
{
method:'POST',
sendContent:qry,
headers: {"Content-Type":"application/x-www-form-urlencoded"}
});
//this callback fires when the XHR returns successful
d.addCallback(function (result)
{
log('save successful');
});
//this callback fires when the XHR fails
d.addErrback( function (result)
{
log('save failed');
});
Nuts!
My ISP crashed and consequently went out of business. I have moved my blog. For new articles visit blog.infoentropy.com
tags in Articles
User login
Other blogs
Recent blog posts
- Step-by-step to build a facebook app with CakePHP
- Enabling CakePHP 1.1 on Lighttpd 1.5
- Install and configure PHP5 and lighttpd on mac os x 10.4
- lighttpd as a startup item on os x
- Mac tips for Unix users
- Moving your cursor in a terminal with bash shell (Mac OS X, and Ubuntu Linux compatible)
- linux user management commands
- Setup LigHTTPD virtual hosting by hand
- Reload your hosts file in Mac
- Using MochiKit doXHR
