Home > Web Front-end > JS Tutorial > body text

Discussion on the problem of obtaining the return value of another function from a function in js_javascript skills

WBOY
Release: 2016-05-16 17:13:13
Original
1527 people have browsed it
Copy code The code is as follows:

//This is asynchronous, and it doesn’t wait for ajax to finish assigning the value. The function returns.
function getCaseInfoForMap(){
var formInfo=$("#firstForm").serialize();
var dd;
$.ajax({
type:"post",
url:"<%=path %>/webmodule/constructionDecision/WjInfo/getCaseInfoForMap.do?timeType=" timeType "&gridNumber=" gridNumber,
dataType:"json",
data:formInfo,
success:function(data){
dd=data;
}
});
return dd;//
}
//Test
function test (){
var data=getCaseInfoForMap();
alert(data[0].caseId);
}

Copy code The code is as follows:

//This is synchronous async:false, ajax will not return until it is completed
function getCaseInfoForMap(){
var formInfo=$("#firstForm").serialize();
var dd="";
$.ajax({
type:"post",
url:"< ;%=path %>/webmodule/constructionDecision/WjInfo/getCommCaseInfoCount.do?timeType=" timeType "&gridNumber=110105217",
dataType:"json",
data:formInfo,
async:false ,
success:function(data){
dd=data;
}
});
return dd;
}
//Test
function test( ){
var data=getCaseInfoForMap();
alert(data);

}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template