Results 1 to 3 of 3

Thread: What does ".then" mean in JavaScript?

  1. #1
    Join Date
    Feb 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What does ".then" mean in JavaScript?

    What does ".then" mean in JavaScript?

    Consider this snippet of code:


    Code:
    return ajaxService.request('post', 'api/{ticketId}/alt-forms/getSatelliteMapUrl', geoCodedata, { failureMessage: 'Failed to Geocode SatMap/PDF'})
                                .then(function (satelliteMapData, data) {


    Is the ".then" comment attached immediately to the previous "return" statement? If so, how? If not, then would the functionality of this JavaScript bit not be impacted if I put an "alert" statement immediately before the ".then" statement and immediately after the "return" statement?

  2. #2
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    509
    Thanks
    9
    Thanked 59 Times in 57 Posts

    Default

    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,496
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It's not always applicable. When it is, it either means (if unqualified) "on success", or if qualified by an indication of then in which case (situation), then in that case. In the context in which you have presented it in your post, most likely it means in case the ajax call is successful, then execute a function (only the beginning of which is shown in your post):

    Code:
    function (satelliteMapData, data) {
    Which is also dependent upon other code as to what exactly that means. Likely it means to map some data either to a data base, or more likely in this case, to a graphic map of some kind on the page, or perhaps, since PDF is mentioned, to a PDF file somewhere.

    And to answer your other question, yes. It is immediately dependent upon the previous line, in fact a continuation of it. The two lines could as easily be written:

    Code:
    return ajaxService.request('post', 'api/{ticketId}/alt-forms/getSatelliteMapUrl', geoCodedata, { failureMessage: 'Failed to Geocode SatMap/PDF'}).then(function (satelliteMapData, data) {
    So, no. You cannot interpose an alert in there without breaking the code. If you wanted to test things you could temporarily change it to:

    Code:
    return ajaxService.request('post', 'api/{ticketId}/alt-forms/getSatelliteMapUrl', geoCodedata, { failureMessage: 'Failed to Geocode SatMap/PDF'})
                                .then(function (satelliteMapData, data) {alert(data);
    That would give you some idea of what 'data' represents. Probably an object though, so if you work with the console at all, more information could be got there by:

    Code:
    return ajaxService.request('post', 'api/{ticketId}/alt-forms/getSatelliteMapUrl', geoCodedata, { failureMessage: 'Failed to Geocode SatMap/PDF'})
                                .then(function (satelliteMapData, data) {console.log(data);
    In any case, it's in the unseen in your post following lines of code that 'data' is utilized. Most likely by the satelliteMapData function, but we cannot know that for certain from such a small amount of code.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Replies: 4
    Last Post: 02-11-2008, 02:38 PM
  2. Javascript.AJAX link inside javascript dropdownmenu
    By Possemaster in forum JavaScript
    Replies: 2
    Last Post: 01-25-2008, 09:46 AM
  3. 3rd javascript not supporting in side the javascript program
    By raju in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 03-24-2007, 10:34 AM
  4. [Ajax XML Ticker ] javascript execute in javascript
    By Borsti26 in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 02-21-2007, 04:33 PM
  5. [Javascript] Class-Based Javascript Analog Clock
    By ByteMyCode in forum Submit a DHTML or CSS code
    Replies: 2
    Last Post: 10-14-2006, 10:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •