Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax Callback

 
Aggarwal Arpit
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello? Is this microphone on?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use code tags when you post code!

Use a closure


 
Aggarwal Arpit
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic