一段自用javascript代码

function jsontoarray(mjson)
{
    var arr = [];
    var i = 0;
    for(var x in mjson.data){
        arr[i] = new Array();
        arr[i][0] = parseInt(String(x), 10); //String(x);  arr[i][1] = parseInt(String(mjson.data[x]), 10);
        i = i+1;
    }
    arr.sort(function(x, y){
        //alert(x[0]);  //alert(y);  //return x[0].localeCompare(y[0]); //字符串比较大小  return x[0]>y[0]; //整形比较大小  });
    //var newarr[];  for (i=0;i<arr.length;i++)
        arr[i][0] = arr[i][0]+mjson.xunit;
    return arr;
}

function jsontoarrays(mjson)
{
    var arr = [];
    var i = 0;
    for(var x in mjson.data){
        arr[i] = new Array();
        arr[i][0] = String(x);
        arr[i][1] = parseInt(String(mjson.data[x]), 10);
        i = i+1;
    }
    arr.sort(function(x, y){
        return x[0].localeCompare(y[0]); //字符串比较大小  });
    for (i=0;i<arr.length;i++)
        arr[i][0] = arr[i][0]+mjson.xunit;
    return arr;
}

function isEmpty(obj)
{
    for (var name in obj)
    {
        return false;
    }
    return true;
}

function getURLParam(h,e){var g="";var f=e.toLowerCase();if(f.indexOf("?")>-1){var d=f.substr(f.indexOf("?")+1).toLowerCase();var a=d.split("&");for(var c=0;c<a.length;c++){if(a[c].indexOf(h.toLowerCase()+"=")==0){var b=a[c].split("=");g=b[1];break;}}}return g;}
//wd = getURLParam('wd', window.location.href);  function ajaxjson(mMethod, mUrl, mCallback, mData)
{
        //声明对象实例  var xmlhttp = false;

    function getHTTPRequestObject()
    {
        try  {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try  {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(E)
            {
                xmlhttp = false;
            }
        }
        if(!xmlhttp && typeof XMLHttpRequest!= 'undefined')
        {
            xmlhttp = new XMLHttpRequest();
        }
    }
    //回调处理  function callback()
    {
            if(xmlhttp.readyState == 4)
            {
                if(xmlhttp.status == 200)
                {
                    //alert(xmlhttp.responseText);  mCallback(JSON.parse(xmlhttp.responseText));
                }
            }
    }
    //产生一个XMLHttpRequest对象实例  getHTTPRequestObject();
    // retrieve the JSON text from the local file.  var timestamp = (new Date()).valueOf();
    if (mUrl.indexOf('?')!=-1)
        mUrl = mUrl+"&t="+ timestamp;
    else  mUrl = mUrl+"?t="+ timestamp;

    xmlhttp.open(mMethod, mUrl, false);
    xmlhttp.onreadystatechange = callback;
    if (mMethod == "GET")
        xmlhttp.send(null);
    if (mMethod == "POST")
    {
        xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
        xmlhttp.send(JSON.stringify(mData));
    }
}

你可能感兴趣的:(一段自用javascript代码)