jQuery post() 方法

jQuery 教程 · 2019-03-28 14:38:34

实例 1

使用 HTTP POST 请求从服务器加载数据:

$("button").click(function(){ $.post("demo_test.html",function(data,status){ alert("Data: " + data + "nStatus: " + status); }); });

实例 2

使用 AJAX 的 POST 请求来改变 <div> 元素的文本:

$("input").keyup(function(){ txt=$("input").val(); $.post("demo_ajax_gethint.html",{suggest:txt},function(result){ $("span").html(result); }); });

定义和用法

$.post() 方法使用 HTTP POST 请求从服务器加载数据。

语法

$(selector).post(URL,data,function(data,status,xhr),dataType)

参数 描述
URL 必需。规定将请求发送到哪个 URL。
data 可选。规定连同请求发送到服务器的数据。
function(data,status,xhr) 可选。规定当请求成功时运行的函数。
额外的参数:
  • data - 包含来自请求的结果数据
  • status - 包含请求的状态("success"、"notmodified"、"error"、"timeout"、"parsererror")
  • xhr - 包含 XMLHttpRequest 对象
dataType 可选。规定预期的服务器响应的数据类型。
默认地,jQuery 会智能判断。
可能的类型:
  • "xml" - 一个 XML 文档
  • "html" - HTML 作为纯文本
  • "text" - 纯文本字符串
  • "script" - 以 JavaScript 运行响应,并以纯文本返回
  • "json" - 以 JSON 运行响应,并以 JavaScript 对象返回
  • "jsonp" - 使用 JSONP 加载一个 JSON 块,将添加一个 "?callback=?" 到 URL 来规定回调

点击查看所有 jQuery 教程 文章: https://codercto.com/courses/l/35.html

查看所有标签

How to Solve It

How to Solve It

Zbigniew Michalewicz、David B. Fogel / Springer / 2004-03-01 / USD 59.95

This book is the only source that provides comprehensive, current, and detailed information on problem solving using modern heuristics. It covers classic methods of optimization, including dynamic pro......一起来看看 《How to Solve It》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

html转js在线工具
html转js在线工具

html转js在线工具