2011-09-08 18 views
4

我想通過使用post或訪問我的Flash應用程序的參數訪問日誌腳本文件(例如,log.php)來保存用戶操作的日誌。
Flash是Web應用程序而不是桌面應用程序。

$.post("test.php", {a: 1, b: 2}, function(data) { 
     console.log(data); 
}); 

$。員額的文件:

在jQuery中,JavaScript可以通過使用下面的代碼訪問網站上的其他文件
http://api.jquery.com/jQuery.post/

我認爲下面的ActionScript代碼等同於jQuery的$ .post()。
此代碼是否會導致jQuery的$ .post()不存在的任何問題?
有沒有更簡單和更短的方法來做到這一點?

var loader:URLLoader = new URLLoader(); 
loader.addEventListener(Event.COMPLETE, function():void { 
    trace(loader.data); 
}); 

var variables:URLVariables = new URLVariables(); 
variables.a = 1; 
variables.b = 2; 

var request:URLRequest = new URLRequest("test.php"); 
request.data = variables; 
request.method = URLRequestMethod.POST; 
try { 
    loader.load(request); 
} catch (error:Error) { 
    trace("failed"); 
} 

回答

0

我認爲有3個方式做同樣的...

1. httpService 
2. WebService 
3. RPC 

前兩個是相同的,只是一個協議也是有差別的,並根據我最後一個是最好的選擇。這比其他兩個快8-10倍。 你可以找到所有細節在Adobe網站

+0

感謝。但這3種方式對我來說很難,也許是因爲我不知道mxml。 –

0

我做了一個雅與你的方式DO

function HTTPPost(_URL:String,_UVar:Object,_UEvent:Object){ 
    var _Loader:URLLoader=new URLLoader(); 
    _Loader.addEventListener(Event.COMPLETE,function():void{ 
     if(_UEvent.hasOwnProperty("_Done")) 
     _UEvent._Done(_Loader.data) 
    }); 
    _Loader.addEventListener(IOErrorEvent.IO_ERROR,function():void{ 
     if(_UEvent.hasOwnProperty("_Error")) 
     _UEvent._Error(_Loader.data) 
    }); 
    var _Variables:URLVariables=new URLVariables(); 
    for(var i in _UVar){ 
     _Variables[i]=_UVar[i] 
    } 
    var _Request:URLRequest=new URLRequest(_URL); 
    _Request.data=_Variables; 
    _Request.method=URLRequestMethod.POST; 
    try{ 
     _Loader.load(_Request); 
    }catch(error:Error){ 
     trace("Failed."); 
    } 
} 
//HTTPPost(File URL, post data and event functions) 

然後你使用它,以便:

HTTPPost("URL",{"Variable_1":"Value"},{ 
     "_Done":function(Message){ 
      trace(Message)//print what URL file prints 
     }, 
     "_Error":function(Message){ 
      trace(Message)//print an HT with error info 
     } 
}) 
相關問題