我已经使用jquery ajax从服务器获取值。当方法进入ajax成功或错误时,我需要返回值。如何做到这一点。请指导我。
$.ajax({
cache: false,
async: true,
type: "GET",
timeout:6000,
dataType: "json",
url:url +"log",
data: { ContactEmail : $("#username").val()},
contentType: "application/json;charset=utf-8",
success: function (result)
{
//Here I need to return the result and should get in another method
},
Error: function (e)
{
//Here I need to return the result and should get in another method
}
});
更新
例如 ,当我调用checkNetConnection()时,它返回值。我需要这样
function checkNetConnection()
{
var netresult=0;
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.NONE] = 'No network connection';
if(states[networkState]=='Ethernet connection'||states[networkState]=='WiFi connection' || states[networkState]=='Cell 2G connection' || states[networkState]=='Cell 3G connection' || states[networkState]=='Cell 4G connection')
{
netresult=1;
}
else
{
netresult=0;
}
return netresult;
}