- 1、js中怎樣使用ajax通過post提交數組數據?php在後台怎樣獲取數組數據?
- 2、簡單的ajax.post方法的問題
- 3、請給個jQuery ajax – post()方法的例子, 發送數據返回結果
- 4、JS與Ajax Get和Post在使用上的區別實例詳解
- 5、jQuery中ajax – get() 方法實例詳解
- 6、jquery中ajax中post方法傳遞參數
有一個參數type:post,這個是以post方式進行提交,data:function(){裡面是返回的數據}
$document.ready(function(){ })這麼寫應該是錯誤的吧,
應該是 $(document).ready(function(){})
String name = request.getParameter(“params”);
這樣取參數應該取不到吧,你上面傳參數的正確格式是這樣的:
{“a”:”data”};
String name = request.getParameter(“params”);這裡的參數應該是上面傳的參數的key值;應該是
String name = request.getParameter(“a”);
$(“button”).click(function(){
$.post(“demo_test_post.asp”,
{
name:”Donald Duck”,
city:”Duckburg”
},
function(data,status){
alert(“Data: ” + data + “\nStatus: ” + status);
});
});
$.post() 的第一個參數是我們希望請求的 URL (“demo_test_post.asp”)。
然後我們連同請求(name 和 city)一起發送數據。
“demo_test_post.asp” 中的 ASP 腳本讀取這些參數,對它們進行處理,然後返回結果。
第三個參數是回調函數。第一個回調參數存有被請求頁面的內容,而第二個參數存有請求的狀態。
提示:這個 ASP 文件 (“demo_test_post.asp”) 類似這樣:
%
dim fname,city
fname=Request.Form(“name”)
city=Request.Form(“city”)
Response.Write(“Dear ” fname “. “)
Response.Write(“Hope you live well in ” city “.”)
%
原生js我不太明白,因為ajax是再太複雜了。
這裡我可以說一下jQuery的ajax,我也是初學者,下面是我理解的:
$.ajax相對於$.get和$.post封裝的比較底層,$.post比$.get封裝的要底層,
越高層的使用起來越簡單,越底層功能越強大。
在jquery中使用get,post和ajax方法給伺服器端傳遞數據,在上篇文章給大家分享了jquery中ajax-post()方法實例,下面通過本文繼續學習jQuery中ajax
–
get()
方法,具體介紹請看下文。
jQuery
Ajax
參考手冊
實例
使用
AJAX
的
GET
請求來改變
div
元素的文本:
$(“button”).click(function(){
$.get(“demo_ajax_load.txt”,
function(result){
$(“div”).html(result);
});
});
親自試一試
定義和用法
get()
方法通過遠程
HTTP
GET
請求載入信息。
這是一個簡單的
GET
請求功能以取代複雜
$.ajax
。請求成功時可調用回調函數。如果需要在出錯時執行函數,請使用
$.ajax。
語法
$(selector).get(url,data,success(response,status,xhr),dataType)
詳細說明
該函數是簡寫的
Ajax
函數,等價於:
$.ajax({
url:
url,
data:
data,
success:
success,
dataType:
dataType
});
根據響應的不同的
MIME
類型,傳遞給
success
回調函數的返回數據也有所不同,這些數據可以是
XML
root
元素、文本字元串、JavaScript
文件或者
JSON
對象。也可向
success
回調函數傳遞響應的文本狀態。
對於
jQuery
1.4,也可以向
success
回調函數傳遞
XMLHttpRequest
對象。
示例
請求
test.php
網頁,忽略返回值:
$.get(“test.php”);
更多示例
例子
1
請求
test.php
網頁,傳送2個參數,忽略返回值:
$.get(“test.php”,
{
name:
“John”,
time:
“2pm”
}
);
例子
2
顯示
test.php
返回值(HTML
或
XML,取決於返回值):
$.get(“test.php”,
function(data){
alert(“Data
Loaded:
“
+
data);
});
例子
3
顯示
test.cgi
返回值(HTML
或
XML,取決於返回值),添加一組請求參數:
$.get(“test.cgi”,
{
name:
“John”,
time:
“2pm”
},
function(data){
alert(“Data
Loaded:
“
+
data);
});
jquery
ajax
的
$.get()用法詳解
js文件
$(document).ready(function(){
$(“form”).submit(function(event)
{event.preventDefault()})//取消submit的默認行為
$(“form
input[type=’submit’]”).click(function(){
var
url
=
$(‘form’).attr(‘action’);
//
取Form中要提交的鏈接
var
param
=
{};
//
組裝發送參數
param[‘name’]
=
$(‘form
input[name=name]’).val();
param[‘age’]
=
$(‘form
input[name=age]’).val();
$.get(url,
param,
function(dom)
{
$(‘div.get’).append(dom)
})
;
//
發送並顯示返回內容
});
})
html文件
form
action=”ajax.php”
method=”get”
Name:
input
type=”text”
name=”name”
/
Age:
input
type=”text”
name=”age”
/
input
type=”submit”
/
/form
div
class=”get”這是ajax的get方法/div
php文件
error_reporting(0);
if($_GET[“name”]==”kitty”)
{
$name=
“you
are
the
lucky”;
}
else
$name=$_GET[“name”];
$age=$_GET[“age”];
echo
“div
“.$name.”
“.$age.”/div”;
以上介紹就是本文給大家分享的jQuery中ajax
–
get()
方法實例詳解,希望大家喜歡。
jQuery ajax – post() 方法:
1、定義和用法:
post() 方法通過 HTTP POST 請求從伺服器載入數據。
2、語法:
jQuery.post(url,data,success(data, textStatus, jqXHR),dataType)
url :必需。規定把請求發送到哪個 URL。
data :可選。映射或字元串值。規定連同請求發送到伺服器的數據。
success(data, textStatus, jqXHR): 可選。請求成功時執行的回調函數。
dataType :可選。規定預期的伺服器響應的數據類型。默認執行智能判斷(xml、json、script 或 html)。
原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/126584.html