$.post()用法
$.post(url,parameters,callBackFunction)
url:abc.ashx, parameters:{name:"lsun",address:"china"}, callBackFunction:成功的回调函数
在abc.ashx里面使用content.request["name"]获取对象
$(function(){
$("input[@type=button]").click(function()
{
$.ajax({url:"abc.ashx",type:"post",data:{name:"liqi",address:"china shanghai"},dataType:"html",
timeOut:2000,error:function(){},success:function(data){alert(data);}});
});
});
三.$.get("h.ashx",{"term":"liqi"},function(data)
{
});
string ps=context.Request.QueryString["term"].ToString();
处理JSON
// $.getJSON("b.json",function(data)
// {
// $.each(data,function(entryIndex,entry){
// var ss="";
// ss+=entry["term"];
// ss+=entry["part"];
// ss+=entry["definition"];
// alert(ss);
// });
// });
b.json:
[{
"term":"terry",
"part":"n.",
"definition":"a convenient deity invented by the ancients",
"quote":["is public worship,then ,a sin",
"this for devotions paid to bacchus",
"the lictors dare to run us in"],
"author":"jorace"
},
{
"term":"backbite",
"part":"v.t.",
"definition":"to speak of a man as you find him when "
},
{
"term":"beadr",
"part":"n.",
"definition":"the hair is commonly hello kitty"
}
]
--------------------
// $.each({"name":"liqi","address":"china"},function(index,value){
// alert(index+value);
// })
处理xml文件
$.get("d.xml",function(data){
// $(data).find("entry").each(function()
// {
// var $entry=$(this);
// var html="";
// html+=$entry.attr("term");
// html+=$entry.attr("part");
// html+=$entry.find("definition").text();
// var $quote=$entry.find("quote");
// if($quote.length)
// {
// $quote.find("line").each(function()
// {
// html+=$(this).text();
// });
// }
// if($quote.attr("author"))
// {
// html+=$quote.attr("author");
// }
// alert(html);
jquery XML:
var x = $(
"<xml><products><product id=/"P1/">AA</product>" +
"<product id=/"P2/">BB</product>" +
"<product id=/"P3/">CC<part>X</part></product></products></xml>");
alert(x.find("products product").size());
alert(x.find("product:eq(1)").attr("id"));
alert(x.find("product").eq(2).find("part").text());
alert(x.find("product[@id='P1']").text());
PS: 在jQuery裡,如果要直接將字串轉成XML物件,記得前後方要加上
Server:
Response.ContentType = "text/xml";
Response.Charset = "UTF-8";
//Response.Write("<?xml version=/"1.0/" encoding=/"UTF-8/" ?>");
//Response.Write("<family>");
//Response.Write("<father>ChenWei</father>");
//Response.Write("<mather>MeiXia</mather>");
//Response.Write("</family>");
Response.End();
client:
$.ajax({
url: 'w.aspx',
dataType:"xml",
error: function(xhr) { },
success: function(response)
{
alert($(response).find("father").text());
}
});