ajax function

2012年4月2日 发表评论 阅读评论

var sajax_debug_mode = false;
var sajax_request_type = “GET”;
var baseUrl = “./”;
var d = new Date();
function sajax_debug(text)
{
if (sajax_debug_mode)
{
      alert(“Debug Information: ” + text);
}
}

function sajax_init_object()
{
sajax_debug(“sajax_init_object() called..”);
var XHttp;
try
{
   XHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
   try
   {
    XHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
   }
   catch (e)
   {
             try
             {
                 XHttp=new XMLHttpRequest();
             }
             catch(e)
             {
                 XHttp = null;
             }
   }
}
if (!XHttp)
   sajax_debug(“Could not create connection object.”);
return XHttp;
}

function sajax_do_call(sURL)
{
oXHtml = sajax_init_object();
oXHtml.open(“GET”, sURL, false);
oXHtml.send(”);
rtnContent = oXHtml.responseText;
delete oXHtml;
return rtnContent;
}

function sajax_post_call(sURL,postStr)
{
oXHtml = sajax_init_object();
oXHtml.open(“POST”, sURL, false);
oXHtml.setRequestHeader(“Content-Type”,”application/x-www-form-urlencoded”);
oXHtml.send(postStr);
rtnContent = oXHtml.responseText;
delete oXHtml;
return rtnContent;
}

function example(vid)
{
     var num = Math.floor(Math.random()*10+1);
     return sajax_do_call(baseUrl+”example.php?vid=”+vid+”&n=”+num);
}


转载请注明来自:[MSN Spaces]http://msn.shandian.biz/395.html

  1. 本文目前尚无任何评论.