Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3854660
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:39:25+00:00 2026-05-19T17:39:25+00:00

//******************Example for multiple ajax success and failure*************// function doAjax1(){ var data=ajax_mode=request1&sample_data1=sample_data1; return $.get(ajax.php,data,function(msg){ //alert(msg);

  • 0
//******************Example for multiple ajax success and failure*************//
    function doAjax1(){
        var data="ajax_mode=request1&sample_data1=sample_data1";
        return $.get("ajax.php",data,function(msg){
            //alert(msg);
        });
    }

    function doAjax2(){
        var data="ajax_mode=request2";
        return $.get("ajax.php",data,function(msg){
            //alert(msg);
        });
    }

//success and error cant be used with $.when()
    $.when( doAjax1(), doAjax2() ).then(function(msg){
        alert('alert oncompletion of both ajax'+msg); //Not returns both ajax result 
      console.log( 'I fire once BOTH ajax requests have completed!' );
   }).fail(function(){
      console.log( 'I fire if one or more requests failed.' );
   }).done(function(){
      console.log( 'I fire if one or more requests done.' );
   });
//****************************************************************************//

PHP Codes ajax.php

<?php
if( isset($_REQUEST['ajax_mode']) )
{
    $ajax_mode=trim($_REQUEST['ajax_mode']);
    switch($ajax_mode){

    case 'request1':
    $sample_data1=$_REQUEST['sample_data1'];
    $checking="checking ajax req 1";
    echo $sample_data1;
    break;

    case 'request2':
    $checking="checking ajax req 2";
    echo $checking;
    break;

    }
}
?>

Question: function doAjax1, doAjax2 returns the value from server.
I am going to use $.when() for multiple ajax request

i need to get all ajax return values once all ajax request had done.

i had used $.when().then(function(msg){alert(msg)})

Result of alert sample_data1,success,[object Object][Please Explain me why it alerts like this]

My Expected alert result sample_data1, sample_data2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:39:26+00:00Added an answer on May 19, 2026 at 5:39 pm
    $.when(doAjax1(), doAjax2())
      .then(myFunc, myFailure);
    // Execute the function myFunc when both ajax requests are successful, 
    // or myFailure if either one has an error.
    
    myFunc = function(a1,  a2){
        /* a1 and a2 are arguments resolved for the 
            doAjax1 and doAjax2 ajax requests, respectively */
       var jqXHR1 = a1[2]; /* arguments are [ "success", statusText, jqXHR ], this explains why you got `sample_data1,success,[object Object]` in your alert */
       alert(jqXHR1.responseText);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In python, you can have a function return multiple values. Here's a contrived example:
For example, let's take the format of a forum, where we have multiple users
What is the syntax for placing constraints on multiple types? The basic example: class
Most of our Eclipse projects have multiple source folders, for example: src/main/java src/test/java When
Is it possible to have a file belong to multiple subpackages? For example: /**
I am building a site in asp.net and have multiple subdomains. For example, one.cookies.com
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
Example: select ename from emp where hiredate = todate('01/05/81','dd/mm/yy') and select ename from emp
example: a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.