jQuery.get(url,[data],[callback])

jQuery.get(url,[data],[callback])

通过远程 HTTP GET 请求载入信息。
这是一个简单的 GET 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。

Load a remote page using an HTTP GET request.
This is an easy way to send a simple GET request to a server without having to use the more complex $.ajax function. It allows a single callback function to be specified that will be executed when the request is complete (and only if the response has a successful response code). If you need to have both error and success callbacks, you may want to use $.ajax.

返回值

XMLHttpRequest

参数

url (String) : 待载入页面的URL地址

data (Map) : (可选) 待发送 Key/value 参数。

callback (Function) : (可选) 载入成功时回调函数。

示例

请求 test.php 网页,忽略返回值。

jQuery 代码:

$.get("test.php");
var url = "../config/chkAjax.ashx?action=chkUserName&userName=" + document.getElementById("editUserName").value;
$.get(url, function (data) {
if (data != "OK") {
           alert(data);
           document.getElementById("editUserName").focus();
           return false;
   }

}); 


请求 test.php 网页,传送2个参数,忽略返回值。

jQuery 代码:

$.get("test.php", { name: "John", time: "2pm" } );

显示 test.php 返回值(HTML 或 XML,取决于返回值)。

jQuery 代码:

$.get("test.php", function(data){
  alert("Data Loaded: " + data);
});

显示 test.cgi 返回值(HTML 或 XML,取决于返回值),添加一组请求参数。

jQuery 代码:

$.get("test.cgi", { name: "John", time: "2pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

JS实现通用效果


var  xmlhttp; function  getReturn(Url)   // 提交为aspx,aspx页面路径, 返回页面的值 { if ( typeof  XMLHttpRequest  !=   " undefined " )
    {
        xmlhttp  =   new  XMLHttpRequest();
    } else   if (window.ActiveXObject)
    { var  versions  =  [ " MSXML2.XMLHttp.5.0 " , " MSXML2.XMLHttp.4.0 " , " MSXML2.XMLHttp.3.0 " , " MSXML2.XMLHttp " , " Microsoft.XMLHttp " ]; for ( var  i  =   0  ; i  <  versions.length; i ++ )
        { try
            {
                xmlhttp  =   new  ActiveXObject(versions[i]); break ;
            } catch (E)
            {
            }
        }
    } try  
    {
        xmlhttp.open( ' GET ' ,Url, false );   
        xmlhttp.setRequestHeader( ' Content-Type ' , ' application/x-www-form-urlencoded ' )
        xmlhttp.send( null );     if ((xmlhttp.readyState  ==   4 ) && (xmlhttp.status  ==   200 ))
        { return  xmlhttp.responseText;
        } else
        { return   null ;
        }
    } catch  (e) 
    {  
         alert( " 你的浏览器不支持XMLHttpRequest对象, 请升级 " ); 
    } return   null ;
}

 调用:

   result  =  getReturn( ' ajaxupgrade.aspx?op=unzip ' ); if  (result  !=   "" ) {
      document.getElementById( " unzip "   +  i).src  =   " ../Img/state1.gif " ;
   }  else  {
      document.getElementById( " unzip "   +  i).src  =   " ../Img/state2.gif " ;

   } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值