试图让程序等待jquery请求的返回。 [英] Trying to get a program to wait for the return from a jquery request.

查看:55
本文介绍了试图让程序等待jquery请求的返回。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,每次按下按钮时都需要获取一些新数据,然后使用该数据继续执行。我已经阅读了大量的建议,似乎没有任何工作,所以我必须做错事。这是调用函数:

I have a program that needs to get some fresh data every time a button is pushed, then use that data to continue execution. I have read through a ton of suggestions bit none seem to work so i must be doing something wrong. This is the calling function:

function _onSpin(iNumBettingLines,iCoin,iCurBet) {
    if(iCurBet > s_aSession["iMoney"]){
        _dieError("INVALID BET: "+iCurBet+",money:"+s_aSession["iMoney"]);
        return;
    }
 makeNextResult(s_aSession["user_name"],s_aSession["coin_bet"],s_aSession["coin_bet"]);
	  responce_string = getNextResults();
    	_Result = [];
        var res_string = parseResult(response_string);
        var incomming = res_string.split("#");
        var this_ln;
        var x = 0;
        var bFreespin = 0;
        var bBonus = 0;
        var reel_pos;
        var bet_amt = 25;
        for(i=0;i<=incomming.length-1;i++){
       	   this_ln=incomming[i].split(",");
       	  _Result[i]=this_ln;
        }          
      }
      _initSettings();
      //$(s_oMain).trigger("bet_placed",{bet:iCoin,tot_bet:iCurBet});
      var rls;
      for(a=0;a<=_Result.length-1;a++){
      	if(_Result[0][0]==bet_amt){
      		rls = _Result[0][3];
      		break;
      	}
      }
  		if(rls!="undefined"){
       reel_pos =rls.split("*");
       for(a=0;a<reel_pos.length;a++){
          fs = reel_pos[a].split("%");
          _aFinalSymbols[a] = new Array(); 
          _aFinalSymbols[a][0] = fs[0];
          _aFinalSymbols[a][1] = fs[1];
          _aFinalSymbols[a][2] = fs[2];
          _aFinalSymbols[a][3] = fs[3];
          _aFinalSymbols[a][4] = fs[4];
  		 }
       
      }
       if(_Result[0][1]==0){
          var str = JSON.stringify(_aFinalSymbols);
          //_oInterface.refreshTotalBet();
          return "res=true&win=false&pattern="+JSON.stringify(_aFinalSymbols)+"&money="+s_aSession["iMoney"]+"&freespin="+s_aSession["iTotFreeSpin"]+"&bonus=false&bonus_prize=-1";
       }
   
      aRet = stuffResults(bet_amt);
      var str = JSON.stringify(_aFinalSymbols);
     // _oInterface.refreshTotalBet();
      return "res=true&win=true&pattern="+_aFinalSymbols+"&win_lines="+JSON.stringify(aRet)+"&money="+s_aSession["iMoney"]+
           "&tot_win="+iTotWin+"&freespin="+s_aSession["iTotFreeSpin"]+"&bonus="+s_aSession["bBonus"]+"&bonus_prize="+iPrizeReceived+"&cash="+s_aSession["iSlotCash"] ;
}





注意responce_string = getNextResults();



以下是getNextResults的代码()





notice the line "responce_string = getNextResults();"

Here is the code for getNextResults()

function getNextResults(){
  foo(function(result) {
     return result;
  });
}





最后foo函数



And finally the foo function

function foo(result) {
   var url = "http://server678.net/ExampleService.asmx";
    $.support.cors = true;
    $.ajax({
        type: "POST",
        url: url,
        contentType: "text/xml",
        dataType: "xml",
        data: _SoaMessage,
        processData: true, 
        success: function (data, status, req) {
           result(req.responseText);
        }
    });
}





该程序调用getnextResult,但不是希望函数返回一个值,它只是吹过它并且响应字符串总是未定义。



我尝试过:



我已经研究了好几天了,似乎没什么用。请帮忙。



The program calls getnextResult but instead of waining for the function to return a value it just blows right through it and response string is always undefined.

What I have tried:

I have been researching this for days and nothing seems to work. Please help.

推荐答案

(s_oMain).trigger(bet_placed,{bet:iCoin,tot_bet:iCurBet});
var rls;
for(a = 0; a< = _ Result.length-1; a ++){
if(_Result [0] [0] == bet_amt){
rls = _Result [0] [3];
休息;
}
}
if(rls!=undefined){
reel_pos = rls.split(*);
for(a = 0; a< reel_pos.length; a ++){
fs = reel_pos [a] .split(%);
_aFinalSymbols [a] = new Array();
_aFinalSymbols [a] [0] = fs [0];
_aFinalSymbols [a] [1] = fs [1];
_aFinalSymbols [a] [2] = fs [2];
_aFinalSymbols [a] [3] = fs [3];
_aFinalSymbols [a] [4] = fs [4];
}

}
if(_Result [0] [1] == 0){
var str = JSON.stringify(_aFinalSymbols);
// _ oInterface.refreshTotalBet();
返回res = true& win = false& pattern =+ JSON.stringify(_aFinalSymbols)+& money =+ s_aSession [iMoney] +& freespin =+ s_aSession [iTotFreeSpin ] + &安培;奖金=假安培; bonus_prize = -1\" ;
}

aRet = stuffResults(bet_amt);
var str = JSON.stringify(_aFinalSymbols);
// _oInterface.refreshTotalBet();
返回res = true& win = true& pattern =+ _ aFinalSymbols +& win_lines =+ JSON.stringify(aRet)+& money =+ s_aSession [iMoney] +
& tot_win =+ iTotWin +& freespin =+ s_aSession [iTotFreeSpin] +& bonus =+ s_aSession [bBonus] +& bonus_prize =+ iPrizeReceived +& cash = + s_aSession [iSlotCash];
}
(s_oMain).trigger("bet_placed",{bet:iCoin,tot_bet:iCurBet}); var rls; for(a=0;a<=_Result.length-1;a++){ if(_Result[0][0]==bet_amt){ rls = _Result[0][3]; break; } } if(rls!="undefined"){ reel_pos =rls.split("*"); for(a=0;a<reel_pos.length;a++){ fs = reel_pos[a].split("%"); _aFinalSymbols[a] = new Array(); _aFinalSymbols[a][0] = fs[0]; _aFinalSymbols[a][1] = fs[1]; _aFinalSymbols[a][2] = fs[2]; _aFinalSymbols[a][3] = fs[3]; _aFinalSymbols[a][4] = fs[4]; } } if(_Result[0][1]==0){ var str = JSON.stringify(_aFinalSymbols); //_oInterface.refreshTotalBet(); return "res=true&win=false&pattern="+JSON.stringify(_aFinalSymbols)+"&money="+s_aSession["iMoney"]+"&freespin="+s_aSession["iTotFreeSpin"]+"&bonus=false&bonus_prize=-1"; } aRet = stuffResults(bet_amt); var str = JSON.stringify(_aFinalSymbols); // _oInterface.refreshTotalBet(); return "res=true&win=true&pattern="+_aFinalSymbols+"&win_lines="+JSON.stringify(aRet)+"&money="+s_aSession["iMoney"]+ "&tot_win="+iTotWin+"&freespin="+s_aSession["iTotFreeSpin"]+"&bonus="+s_aSession["bBonus"]+"&bonus_prize="+iPrizeReceived+"&cash="+s_aSession["iSlotCash"] ; }





注意responce_string = getNextResults();



以下是getNextResults的代码()





notice the line "responce_string = getNextResults();"

Here is the code for getNextResults()

function getNextResults(){
  foo(function(result) {
     return result;
  });
}





最后foo函数



And finally the foo function

function foo(result) {
   var url = "http://server678.net/ExampleService.asmx";


.support.cors = true;
.support.cors = true;


.ajax({
type:POST,
url:url,
contentType:text / xml,
dataType:xml,
data:_SoaMessage,
processData:true,
success:function(data,status,req){
result(req.responseText);
}
}) ;
}
.ajax({ type: "POST", url: url, contentType: "text/xml", dataType: "xml", data: _SoaMessage, processData: true, success: function (data, status, req) { result(req.responseText); } }); }





该程序调用getnextResult,但不是希望函数返回一个值,它只是吹过它并且响应字符串总是未定义。



我尝试过:



我已经研究了好几天了,似乎没什么用。请帮忙。



The program calls getnextResult but instead of waining for the function to return a value it just blows right through it and response string is always undefined.

What I have tried:

I have been researching this for days and nothing seems to work. Please help.


这篇关于试图让程序等待jquery请求的返回。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆