// 发送request请求 
// 注意：需要jQuery的支持 
// url:要请求的URL，如：/xxx/AjaxAction.do 
// data:要请求的参数，与url一起构成一个完整的URL请求，如：method=list&id=123 
// callback:回调函数的名称，如：send_request_callback,请求成功后，会调用send_request_callback函数 
function ajax_request(url,data,callback){ 
    jQuery.ajax({ 
       type: "POST",    // GET,POST 
       url: url,   // AjaxAction.do 
       data: data, // method=list&id=123 
       success: function(responseText){ 
           var text = responseText.replace(/\"/g,"\\\""); 
           var commond = callback + "(\"" + text + "\")"; 
           eval(commond); 
       }, 
       error: function (XMLHttpRequest, textStatus, errorThrown) { 
           var commond = callback + "(\"\")"; 
           eval(commond); 
       } 
    }); 
} 

function ajax_requesttext(url,data){ 
    jQuery.ajax({ 
       type: "POST",    // GET,POST 
       url: url,   // AjaxAction.do 
       data: data, // method=list&id=123 
       success: function(responseText){ 
           var text = responseText.replace(/\"/g,"\\\""); 
           return text;
       }, 
       error: function (XMLHttpRequest, textStatus, errorThrown) { 
           return "错误"; 
       } 
    }); 
}


// 将某DIV层定位到parent的正下方 
// 用于类似Google搜索框中下拉提示框的功能，需要和Ajax结合使用 
function relocation(parent,div_id){ 
    var offsetLeft = parent.offsetLeft;  // parent相对父元素的左端端偏移量 
    var offsetTop = parent.offsetTop;    // parent相对父元素的顶端偏移量 
    var offsetHeight  = parent.offsetHeight;  // parent的高度 

    // 循环获得元素的父级控件，累加左和顶端偏移量 
    var obj = parent.offsetParent; 
    while (obj) { 
        offsetLeft += obj.offsetLeft; 
        offsetTop += obj.offsetTop; 
        obj = obj.offsetParent; 
    } 

    var div_obj = document.getElementById(div_id); 
    div_obj.style.position = "absolute"; // 设定child为绝对位置 
    div_obj.style.left = offsetLeft + "px";    // 设置child的相对左方的距离 
    div_obj.style.top = (offsetTop + offsetHeight) + "px";  // 设置child的相对上方的距离 
} 



