如何進(jìn)行JSON 數(shù)據(jù)客戶端進(jìn)行傳輸
您可以用 JSON 傳輸一個簡單的 String,Number,Boolean,也可以傳輸一個數(shù)組,或者一個復(fù)雜的 Object 對象,我們先討論如何在 Web 頁面中用 JavaScript 處理 JSON 數(shù)據(jù)。我們通過一個簡單的 JavaScript 方法就能看到客戶端如何將 JSON 數(shù)據(jù)表示給用戶:
- scriptscript.onload = script.onreadystatechange = function(){
- this.readyState == "loaded" || this.readyState == "complete") ) {
- done = true;
- success();//這里
- complete();
- head.removeChild( script );
- }
- };
- 大概看了一下,當(dāng)script load結(jié)束時,執(zhí)行success(),complete()方法
- 在看后面
- function success(){
- if ( s.success )
- s.success( data, status );//執(zhí)行內(nèi)部函數(shù)success,如果你有callback那么就執(zhí)行你的callback并且把data和狀態(tài)傳進(jìn)去
- if ( s.global )jQuery.event.trigger( "ajaxSuccess", [xhr, s] );
- }
- function complete(){
- if ( s.complete )
- s.complete(xhr, status);
- if ( s.global )
- jQuery.event.trigger( "ajaxComplete", [xhr, s] );
- if ( s.global && ! --jQuery.active )
- jQuery.event.trigger( "ajaxStop" );
- }
如果有提交數(shù)據(jù),也就是jquery ajax的datar屬性不空的情況下不為空的情況:
1.發(fā)送一個空對象調(diào)用無參數(shù)的WebService要領(lǐng);#t#
2.請一個有參數(shù)的WebService要領(lǐng),一定要配置JSON 數(shù)據(jù),并且不能手工配置 Content-Type了。