解决方案 »

  1.   

    function ajaxtest(url){
      return $.ajax({ 
               type: "get",
                url:url,
                timeout: 5000,
                data: {type:"info"}, 
                cache:false,
                success:function(xmlDoc, textStatus, xhr){ 
                    if(xhr.readyState==4)
                    {
                        if(xhr.status == 200)
                        {
                          var str=xhr.responseText; //获取返回值
                        }//200
                    }//4
                }, 
                error: function(xhr, textStatus, errorThrown)
                {
                    if("timeout" == textStatus)
                    {
                        alert("请求超时");
                    }
                    else
                    {
                        alert("网络异常");
                    }
                }
            }); //ajax结束
    }
      

  2.   


    function ajaxtest(url,data,callback){
      $.ajax({ 
               type: "get",
                url:url,
                timeout: 5000,
                data: data, 
                cache:false,
                success:function(xmlDoc, textStatus, xhr){ 
                    if(xhr.readyState==4)
                    {
                        if(xhr.status == 200)
                        {
                          var str=xhr.responseText; //获取返回值
                          if(callback){
                                 callback(str);
                          }
                        }//200
                    }//4
                }, 
                error: function(xhr, textStatus, errorThrown)
                {
                    if("timeout" == textStatus)
                    {
                        alert("请求超时");
                    }
                    else
                    {
                        alert("网络异常");
                    }
                }
            }); //ajax结束
    }
      

  3.   

    jquery ajax已经封装的够通用了$.ajax
    $.post
    $.get
    $.getJSON
    $.getScript都可以用, 没有必要自己再去封闭一遍