ITeye博客

JQuery 实践Ajax

leiwuluan · 2009-10-03 11:53 · JQuery · Ajax · PHP · XML · jQuery · CGI · Markdown

JQuery.get(url,data,callback);

 

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

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

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

 

示例
请求 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.post(url,data,callback);

 

 

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

--------------------------------------------------------------------------------

Load a remote page using an HTTP POST request.This is an easy way to send a simple POST 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) : 发送请求地址。

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

callback (Function) : (可选) 发送成功时回调函数。

评论(3)

  1. #3 楼 · leiwuluan · 2010-07-13 00:01

    有啊当然可以共享了!

  2. #2 楼 · spp_1987 · 2010-07-12 08:29

    是关于它们的ajax的例子??

  3. #1 楼 · spp_1987 · 2010-07-12 08:27

    楼主有没有啊 关于struts1.3 跟jquery的例子啊?

评论功能维护中,当前仅展示历史评论。