jquery傳送ajax請求返回資料格式

2022-03-23 02:41:22 字數 720 閱讀 6839

jquery向伺服器傳送乙個ajax請求後,可以返回多種型別的資料格式,包括:html,xml,json,text等。

1.html格式的資料

""+username+" :

"+content+"

"伺服器端返回資料格式是html片段,因此不需要經過處理就可以將新的html資料插入到主頁面中,這種方法雖然簡便,但是重用性不強。

$.ajax(,

success:function(data)

}2.xml格式的資料

response.write("<?xml version=""1.0"" encoding=""utf-8""?>") response.write("") response.write("") response.write(""+content+"") response.write("") response.write("")

response.end();

由於伺服器端返回的資料格式是xml文件,因此需要對文件的資料進行處理。

$.ajax(,

success:function(data)

}3.json格式的資料

response.write("") 

由於伺服器端返回的資料格式是json文件,因此也需要對文件的資料進行處理,但是json文件比較xml文件更容易解析。

$.ajax(,

success:function(data)

}

jQuery傳送Ajax請求

ajax cache false,async true,type post datatype json xml html success function result ajax cache false,async false,type post datatype json xml html suc...

jQuery傳送Ajax請求

ajax cache false,async true,type post datatype json xml html success function result ajax cache false,async false,type post datatype json xml html suc...

傳送Ajax請求

get請求傳送資料量較小,不能大於2kb,引數追加在url後面,看的到明碼的請求引數值。post請求傳送資料量大小不受限制,請求通過http post機制 將請求引數放在html header中傳輸,看不到明碼的請求引數值。步驟一 建立非同步物件 步驟二 設定請求的url引數,引數一是請求的型別,引...