aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Ajax Callback Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Ajax Callback" Watch "Ajax Callback" New topic
Author

Ajax Callback

Aggarwal Arpit
Ranch Hand

Joined: Mar 04, 2012
Posts: 86
Hi, I am having this code in my application and I am not getting what callback is doing in this code.
Please help me.


Thanks In Advance
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Looks like createAddProductsCallBack creates an object of functions.

Those functions are than referenced in the error and success callbacks.

What don't you understand exactly?
Aggarwal Arpit
Ranch Hand

Joined: Mar 04, 2012
Posts: 86
Hi Eric,

Thanks for your reply.
Actually I am not getting what this piece of code is doing:

var options = {
//target: '#output2', // target element(s) to be updated with server response
//beforeSubmit: showRequest, // pre-submit callback
success: callback['success'], // post-submit callback
error: callback['failure'],
// other available options:
url: ctx + '/userarea/addProductsAJAX', // override for form's 'action' attribute
type: 'post', // 'get' or 'post', override for form's 'method' attribute
dataType: 'xml', // 'xml', 'script', or 'json'
data: {p: pid, q: qty}
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
};
As far as I understood options is a javascript variable, whose value is dynamically populated. and then options is passed to ajax call.
But I am not getting what is happening inside options
{
//target: '#output2', // target element(s) to be updated with server response
//beforeSubmit: showRequest, // pre-submit callback
success: callback['success'], // post-submit callback
error: callback['failure'],
// other available options:
url: ctx + '/userarea/addProductsAJAX', // override for form's 'action' attribute
type: 'post', // 'get' or 'post', override for form's 'method' attribute
dataType: 'xml', // 'xml', 'script', or 'json'
data: {p: pid, q: qty}
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
};

How we can pass String in callback variable (callback['success']) ?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Hello? Is this microphone on?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
use code tags when you post code!

Use a closure


Aggarwal Arpit
Ranch Hand

Joined: Mar 04, 2012
Posts: 86
Hi Eric,

I got in what's happening here.Firstly createAddProductsCallBack is read and stored in var callback.
Then it goes to options inside which it goes to url using ajax and on success it is calling the sucess method of createAddProductsCallBack function.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ajax Callback