function GetCutArea(){
value = ChangeAreaUint($('#opUnitID').val(),$('#txtLength').val(),$('#txtWidth').val());
alert(value);
$('#PaperArea').val(value);
}function ChangeAreaUint(beginunitid,OpenLength,OpenWidth){
window.top.jQuery.ajax({
type: "POST",dataType:"json",
url:"../Controller/PEManage/PETypeSetMaster.php",
data:"&action=unitchange"+'&beginunitid='+beginunitid+'&endunitid='+endunitid,
error:function(XMLHttpRequest,textStatus,errorThrown){
window.top.alert(XMLHttpRequest+'<br/>'+textStatus+'<br/>'+errorThrown);
},
success:function(data,type){
if(data==''||data==null){
alert('false');
return null;
}
alert(OpenLength*OpenWidth*data.ConvertRate)
return (OpenLength*OpenWidth*data.ConvertRate);
}
});
}这里弹出来的结果是有的
但是为什么放回到那边去弹出来的就是“undifine”
求指教。

解决方案 »

  1.   

    为什么放回到那边去弹出来的就是“undifine”哪边啊
      

  2.   

    function GetCutArea(){
     value = ChangeAreaUint($('#opUnitID').val(),$('#txtLength').val(),$('#txtWidth').val());
     alert(value);
     $('#PaperArea').val(value);
     }
    这里面不是调用的下面的方法吗,
    返回值用value接收的
    alert的时候“undifine”
      

  3.   

    success:function(data,type){
    这个是回调函数,你这里的return当然是返回这个回调函数而已,不是返回你ChangeAreaUint这个函数的所以外面的value当然是undefined了
    function ChangeAreaUint(beginunitid,OpenLength,OpenWidth){
    var a ;
    window.top.jQuery.ajax({
    type: "POST",dataType:"json",
    url:"../Controller/PEManage/PETypeSetMaster.php",
    data:"&action=unitchange"+'&beginunitid='+beginunitid+'&endunitid='+endunitid,
    error:function(XMLHttpRequest,textStatus,errorThrown){
    window.top.alert(XMLHttpRequest+'<br/>'+textStatus+'<br/>'+errorThrown);
    },
    success:function(data,type){
    if(data==''||data==null){
    alert('false');
    return null;
    }
    alert(OpenLength*OpenWidth*data.ConvertRate)
     a =(OpenLength*OpenWidth*data.ConvertRate);
    }return a
    }
      

  4.   

    ajax是异步的,请将方法放到回调函数里,或者将ajax设置同步function GetCutArea(){
    ChangeAreaUint($('#opUnitID').val(),$('#txtLength').val(),$('#txtWidth').val(), function (value){
    $('#PaperArea').val(value);
    });
    }function ChangeAreaUint(beginunitid,OpenLength,OpenWidth, callback){
    window.top.jQuery.ajax({
    type: "POST",dataType:"json",
    url:"../Controller/PEManage/PETypeSetMaster.php",
    data:"&action=unitchange"+'&beginunitid='+beginunitid+'&endunitid='+endunitid,
    error:function(XMLHttpRequest,textStatus,errorThrown){
    window.top.alert(XMLHttpRequest+'<br/>'+textStatus+'<br/>'+errorThrown);
    },
    success:function(data,type){
    if(data==''||data==null){
    alert('false');
    callback(null);
    } else {
    callback(OpenLength*OpenWidth*data.ConvertRate);
    }
    }
    });
    }
      

  5.   

    4楼的,你的那个方法返回实在success回调后面返回的还是在ajax之外返回?
    6楼的我试试看。