Home >Web Front-end >JS Tutorial >jquery ajax modify global variable sample code_jquery

jquery ajax modify global variable sample code_jquery

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 17:16:35872browse

I encountered a problem at work today
The code is as follows:

Copy the code The code is as follows:

var status=1;
var ob=$("[name='email']");
$.ajax({
url:"{:U('Home/Index/checkemail ')}",
data:"email=" query.email,
type:"post",
dataType:"json",
success:function(re){
status =0;
}
});
alert(status);

In this way, the value that pops up every time is 1;
Because we want to use the returned value Process and change status to its value, check some information
Solution: async:false,
rewritten as:
Copy code The code is as follows:

$.ajax({
async:false,
url:"{:U('Home/Index/checkemail')}",
data:"email=" query.email,
type:"post",
dataType:"json",
success:function(re){
status=0;
}
});
Statement:
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