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

  • Home
  • SEARCH
  • 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 1808638
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:17:11+00:00 2026-05-17T06:17:11+00:00

I have a jquery Ajax call function that I use to submit form to

  • 0

I have a jquery Ajax call function that I use to submit form to database to save.
Also use that to get data from server and show to the user.
When I post\save form data, I must show a result of the post to the user whether there was an error or not.

Everything works fine if I run in synchronous mode. I get the data if I want or get the result after posting using this single method.

But it seems not working in async mode.

How do I pass the data back to the caller? The web service returns the data correctly.
See the alert() I have. It shows me the data.

How can I get data and show to user and post data and show result to user in async mode?
Do I need to create 2 separate functions one for get and other to post?

Here is the function:

function MakeAjaxCall(svr, webmethod_name, op, btn, rslt, bGetData) {
   var data = "";
   var args = '';
   var l = arguments.length;
   if (l > 7) { for (var i = 7; i < l - 1; i += 2) { if (args.length != 0) args += ','; args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"'; } }

   var surl = "http://<myserver>/" + svr + '.aspx';
   $.ajax({
      type: "POST",
      async: (op == "sync") ? false : true,
      url: surl + "/" + webmethod_name,
      data: "{" + args + "}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function ShowSuccess(res) {
         //alert('dfx res:'+res.d);//THIS SHOWS THE DATA FROM SQL CALL FINE
         data = res.d;
      },
      fail: function ShowFail(xhr) {         
         data = "ERROR";
      }
   });
}
  • 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-17T06:17:12+00:00Added an answer on May 17, 2026 at 6:17 am

    Add a callback function? E.g.,

    function MakeAjaxCall(svr, webmethod_name, op, btn,
                          rslt, bGetData, callbackFunction) {
       //removed for brevity
    
       var surl = "http://<myserver>/" + svr + '.aspx';
       $.ajax({
          //removed for brevity
          success: function ShowSuccess(res) {
             //pass the data to the callbackFunction
             callbackFunction(res.d);
          },
          //etc.
       });
    

    Then just pass the function name (or anonymous function) into the MakeAjaxCall function, like so:

    //anonymous function
    MakeAjaxCall(svrVal, somewebmethod_name, opVal, btnVal,
                          rsltVal, bGetDataVal, function(data) { alert(data); });
    
    //named function
    MakeAjaxCall(svrVal, somewebmethod_name, opVal, btnVal,
                          rsltVal, bGetDataVal, alert)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that uses jQuery to submit an ajax post and it
I have some jQuery code. I have called an Ajax function file, file.php, that
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
I am running ASP.NET MVC Beta. I have an AJAX call running through jQuery
I have done jQuery and Ajax, but I am not able to get the
I have developed code with Ajax and jQuery. I have got a response from
Is it possible that using jQuery, I cancel/abort an Ajax request that I have
I have written jQuery code, in files Main.html and ajax.php . The ajax.php file
I have a simple HTML. I am using the JQuery for AJAX purpose. Now,
With ASP.NET MVC, it is common to have AJAX code(e.g. jQuery) to invoke web

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.