zoukankan      html  css  js  c++  java
  • 通过远程 HTTP GET 请求载入信息

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

    概述

    通过远程 HTTP GET 请求载入信息。

    这是一个简单的 GET 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。大理石机械构件

    jQuery 1.12 中 jQuery.post 和 jQuery.get 支持对象参数,这样一来好处还比较多,比如设置回调函数的context,或者跨域 post 时可以withCredential: true。用法可以参考最后一个示例。

    参数

    url,[data],[callback],[type]String,Map,Function,StringV1.0

    url:待载入页面的URL地址

    data:待发送 Key/value 参数。

    callback:载入成功时回调函数。

    type:返回内容格式,xml, html, script, json, text, _default。

    示例

    描述:

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

    jQuery 代码:
    $.get("test.php");

    描述:

    请求 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);
    });

    描述:

    jQuery 1.12 中 jQuery.get()支持对象参数,具体的参数可以参考 $.ajax():

    jQuery 代码:
    jQuery.get({
                url: “/example”
    });
  • 相关阅读:
    html5 悬浮提示框
    ajax 接收json
    ajax 发送参数
    jquery无刷新请求ajax
    jQuery 发送 ajax json 请求
    html5 三级联动菜单
    iframe 用法
    html5 复制文字
    bootstrap表单按回车会自动刷新页面的问题
    jquery版本不兼容问题
  • 原文地址:https://www.cnblogs.com/furuihua/p/12001848.html
Copyright © 2011-2022 走看看