• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Ajax Callback

 
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:)
 
author
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']) ?

 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello? Is this microphone on?
 
Eric Pascarello
author
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.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!