counter
counter

javascript HTTP 请求

1.get方法:对指定的URL进行一个GET请求,该方法带两个参数:URL和回调函数

  http.get(sURL,fnCallBack)

  {

    var bHttpSupport=(typeof XMLHttpRequest=="Object"||"Window.ActiveXObject")

    if(bHttpSpupport)

      {

        var ORequest= new XMLHttpRequest();

        ORequest.open("get",sURL,true);

        ORequest.OnReadyStateChange=function()

          {

            if(ORequest.readystate=="4")

            {

              fnCallBack(ORequest.responseText);

            }

          }

        ORequest,.send(null);

      }

  

  }

2.Post方法:

  

http.get(sURL,sParams,fnCallBack)

  {

    var bHttpSupport=(typeof XMLHttpRequest=="Object"||"Window.ActiveXObject")

    if(bHttpSpupport)

      {

        var ORequest= new XMLHttpRequest();

        ORequest.open("post",sURL,true);

        ORequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

        ORequest.OnReadyStateChange=function()

          {

            if(ORequest.readystate=="4")

            {

              fnCallBack(ORequest.responseText);

            }

          }

        ORequest,.send(sParams);

      }

  }

3.两个脚本被认为是同源的条件:协议相同且端口相同且域名相同。若不满足其一,就不允许两个脚本进行交互。

4.没有声明var 的变量,会被认为是全局window范围内的对象。

posted @ 2012-08-08 15:32  bfy  阅读(443)  评论(0编辑  收藏  举报