ajax的小例子
来源:互联网 发布:淘宝视频审核要多久 编辑:程序博客网 时间:2024/05/02 03:35
load
<!DOCTYPE html><html><head><script src="/jquery/jquery-1.11.1.min.js"></script><script>$(document).ready(function(){ $("button").click(function(){ $("#div1").load("/example/jquery/demo_test.txt h2","data",function(responseTxt,statusTxt,xhr){alert("this is a test"+responseTxt)}); });});</script></head><body><div id="div1"><h2>使用 jQuery AJAX 来改变文本</h2></div><button>获得外部内容</button><pre> <h2>jQuery and AJAX is FUN!!!</h2> <p id="p1">This is some text in a paragraph.</p></pre></body></html>
放到http://www.w3school.com.cn/上执行吧
更多例子详见<div><a href="http://www.w3school.com.cn/jquery/jquery_ajax_load.asp">w2school</a></div>
get: 从指定的资源请求数据
语法:
$.get(URL,callback);
必需的 URL 参数规定您希望请求的 URL。
可选的 callback 参数是请求成功后所执行的函数名。第二个参数是回调函数。第一个回调参数存有被请求页面的内容,第二个回调参数存有请求的状态。
下面的例子使用 $.get() 方法从服务器上的一个文件中取回数据:
<!DOCTYPE html><html><head><script src="/jquery/jquery-1.11.1.min.js"></script><script>$(document).ready(function(){ $("button").click(function(){ $.get("/example/jquery/demo_test.asp",function(data,status){ document.write("数据:" + data + "\n状态:" + status); }); });});</script></head><body><button>向页面发送 HTTP GET 请求,然后获得返回的结果</button></body></html>
提示:这个 ASP 文件 ("demo_test.asp") 类似这样:
<%response.write("This is some text from an external ASP file.")%>
- POST - 向指定的资源提交要处理的数据
$.post() 方法通过 HTTP POST 请求从服务器上请求数据。
语法:
$.post(URL,data,callback);
必需的 URL 参数规定您希望请求的 URL。
可选的 data 参数规定连同请求发送的数据。
可选的 callback 参数是请求成功后所执行的函数名。
下面的例子使用 $.post() 连同请求一起发送数据:
<!DOCTYPE html><html><head><script src="/jquery/jquery-1.11.1.min.js"></script><script>$(document).ready(function(){ $("button").click(function(){ $.post("/example/jquery/demo_test_post.asp", { name:"Donald Duck", city:"Duckburg" }, function(data,status){ alert("数据:" + data + "\n状态:" + status); }); });});</script></head><body><button>向页面发送 HTTP POST 请求,并获得返回的结果</button></body></html>
http://www.w3school.com.cn/example/jquery/demo_test_post.asp内容:
Dear . Hope you live well in .
执行之后弹出框:
HTTP 方法:GET 对比 POST
详见:http://www.w3school.com.cn/tags/html_ref_httpmethods.asp
0 0
- ajax的小例子
- AJAX的小例子
- ajax的小例子
- ajax的小例子
- 简单的ajax小例子
- $.ajax 的简单小例子
- 一个简单的AJAX的小例子
- AJAX AutoComplete简单的小例子
- Struts下实现ajax的小例子
- Struts下实现AJAX的小例子
- 初学AJAX的小例子,XMLHttpRequest对象
- Ajax 和servlet的小例子
- 初学ajax的一个小例子
- 写一个ajax例子的小问题
- ajax获取新闻数据的小例子
- AJAX的异步请求小例子
- 简单的ajax请求小例子
- Ajax最实用的小例子集合
- 那时的我还没剪去长发
- [.Net码农]WPF中Timer与DispatcherTimer类的区别
- Echarts 关于axisLabel中x抽值太长不自动换行的问题
- Redis安装部署
- Eclipse配置C#开发环境
- ajax的小例子
- ViewPager实现左右无限循环滑动
- ganglia 监控 windows
- jquery获取input值的各种情况
- 土豪的定义
- DOM解析原理
- Eclipse配置C/C++开发环境
- 初学struts2笔记---框架结构action等说明
- Telephony之GsmCallTracker(原)