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 9065359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:28:49+00:00 2026-06-16T16:28:49+00:00

function addrewarddb() { var rval=98; $.post(db/mkreward.php,{ proid:getURLParameter(id) },function(data){ rval=99; alert(rval); }); alert(rval); return rval;

  • 0
function addrewarddb()
{
    var rval="98";
    $.post("db/mkreward.php",{
        proid:getURLParameter("id")
    },function(data){


         rval="99";
         alert(rval);
    });
    alert(rval);
     return rval;

}

when this function executes the function returns 98 instead of 99.the two alerts showing 98,then 99.how to make my function returns 99.i think the problem here is the function returnig before the response from the server page mkreward.php.how i can make the function return after the response from server

  • 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-06-16T16:28:50+00:00Added an answer on June 16, 2026 at 4:28 pm

    The $.post call is asynchronous.

    This means that the function returns before the HTTP request has been completed.

    Then, when the $.post() call finishes, it then updates the variable and alerts 99.

    From the jquery docs:

    async Boolean Default: true By default, all requests are sent
    asynchronously (i.e. this is set to true by default). If you need
    synchronous requests, set this option to false. Cross-domain requests
    and dataType: “jsonp” requests do not support synchronous operation.
    Note that synchronous requests may temporarily lock the browser,
    disabling any actions while the request is active. As of jQuery 1.8,
    the use of async: false with jqXHR ($.Deferred) is deprecated; you
    must use the complete/success/error callbacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function checkuser(user) { var ret = false; $.ajax({ type:'POST', url:'user.php', async:false, data:{'user':user}, success:function (data)
function ajaxCheck(){ var inpUs = $(#user).val(); $.post( ./inpCheck.php, { user : inpUs }, function(data)
function genTask(elem){ elem.each(function(){ $this=$(this).parent('.cntTasks'); var pattern=/taskId-(.*)$/ var idTask=$this.attr('id').match(pattern); var data='id_task='+idTask[1]; if(typeof jsVar2 !='undefined') data+=jsVar2;
function f() { var b = b; return function() { alert(b); return b; };
Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object = args.shift(); return
function show_destination(country_id,airport_id){ $.ajax({ type: POST, url: function.php, data: country_id=+country_id+&airport_id=+airport_id+&action=destination, beforeSend: function() { $(#loader_destination).html(''); },
function selected() { var selObj = window.getSelection(); } This function returns selected text from
function correlativo(sucursal){ var tipo=document.getElementById('tipo').value; var correlativo= document.getElementById('correlativo') var ajax=nuevoAjax(); ajax.open(POST, ../ajax/correlativo_ajax.php, true); ajax.setRequestHeader(Content-Type, application/x-www-form-urlencoded);
function Apple(){ this.name=apple; } function Orange(){ this.name=orange; this.apple = new Apple(); this.apple.onCalled=function(){ alert(this.name); }
function getWindowsUserName() { var WinNetwork = new ActiveXObject(WScript.Network); var urlToSite = http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS= + WinNetwork.UserName;

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.